#define question

This is a discussion on #define question within the C Programming forums, part of the General Programming Boards category; can i #define a character. for example the value of the char. 'N' is 78 'E' is 69 'N' + ...

  1. #1
    Unregistered
    Guest

    #define question

    can i #define a character.
    for example the value of the char. 'N' is 78
    'E' is 69
    'N' + 'E' = 147
    i want to #define NE 147
    is this possible??

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    you could do something like this

    Code:
    #include <stdio.h>
    #define ADD_CHAR(a,b)(a+b)
    int main()
    {
    	printf("%d",ADD_CHAR('N','E'));
    	return 0;
    }
    then it would work for any letter.

    just a thought
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Yes
    you can #define NE 147
    so 'N'+'E'==NE would be true.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    #define QUESTION ( 2B || !(2B) )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Hate to be the one to tell ya this Salem, but your code is invalid.
    Code:
    #include <stdio.h>
    
    #define QUESTION ( 2B || !(2B) )
    int main ( void )
    {
    	return printf("%d", QUESTION );
    }
    Compiling...
    test1.c
    c:\windows\desktop\test.c\test1.c(6) : error C2059: syntax error : 'bad suffix on number'
    c:\windows\desktop\test.c\test1.c(6) : error C2146: syntax error : missing ')' before identifier 'B'
    c:\windows\desktop\test.c\test1.c(6) : error C2059: syntax error : 'bad suffix on number'
    Error executing cl.exe.

    test1.exe - 3 error(s), 0 warning(s)


    ...And then, as I was typing this message, I actually _read_ the code. Good one, you got me there. Good show!

    Quzah.

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    lol @ Quzah
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    Originally posted by Salem
    #define QUESTION ( 2B || !(2B) )
    Cool

    How about writing a whole novel in C?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing syscalls from C
    By lilcoder in forum C Programming
    Replies: 17
    Last Post: 09-19-2007, 02:27 PM
  2. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  3. macro (#define) question
    By Darrok in forum C++ Programming
    Replies: 30
    Last Post: 12-20-2001, 04:01 PM
  4. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21