4

Possible Duplicate:
Macro for concatenating two strings in C

How to concatenate two strings with a macro?

I tried this but it does not give correct results:

#define CONCAT(string) "start"##string##"end"
Community
  • 1
  • 1
MOHAMED
  • 41,599
  • 58
  • 163
  • 268

1 Answers1

11

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

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

For two strings:

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

Here is a link to a demo on ideone.

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523