Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string concatenation with macro [duplicate]

Tags:

c

macros

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"
like image 825
MOHAMED Avatar asked Dec 27 '22 10:12

MOHAMED


1 Answers

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.

like image 67
Sergey Kalinichenko Avatar answered Dec 29 '22 01:12

Sergey Kalinichenko