How to contain escape sequences in macro definition #?

520 Views Asked by At

I am trying to use this macro definition in C:

#define STR(x) #x

Is it possible to contain some escape sequences inside x? e.g., I want to define a string like:

char* str = "\'";

This declaration does not seem to work:

char* str1 = STR(\');

If I must use this macro definition, is there some way to contain strings containing apostrophe "\'"? Thanks!

1

There are 1 best solutions below

0
ikegami On BEST ANSWER
const char* img = "/Image/'.png";

can also be written as

const char* img = "/Image/" "'" ".png";

so you could use

#define IMG(x) "/Image/" x ".png"

const char* img = IMG("'");