Concatenating strings with a macro

Possible duplicate:
Macro to concatenate two strings in C

How to combine two lines with a macro?

I tried this, but it does not give the correct results:

#define CONCAT(string) "start"##string##"end" 
+4
source share
1 answer

You need to omit ## : adjacent string literals are automatically concatenated , so this macro will concatenate strings the way you want:

 #define CONCAT(string) "start"string"end" 

For two lines:

 #define CONCAT(a, b) (a"" b) 

Here is a link to a demo on ideone .

+9
source

All Articles