Browse our categories and find questions you could answer!
Services
Questions
Thought of a category that is not present? Contact Us!
C programming: How to insert a define inside a string
Question from Cybercinglet
Reward : 2.00 $
Tuesday, Mar 20, 2007 - 7:30 AM PST
Computer -Programming -C/C++/C#

Hello,

I have been searching for 2 hours how to put a #define inside a C string :

Example :

#define MYNAME john

printf("my name is ##MYNAME##")

Fast and accurate answer appreciated.

ProgrammersGod
Tuesday, Mar 20, 2007 - 7:44 AM PST
ProgrammersGod received 2.00 $ for this answer

Hello Cybercinglet,

C String can be interrupted.

Example: string my_string="my name is" "john";
This has the same effect as "my name is john".

So use :

#define MYNAME "john"

printf("my name is" MYNAME); will work properly.

Regards.