is this possible with macros ?

Started by whatsup, January 12, 2011, 10:16:05 PM

Previous topic - Next topic

whatsup

i need a macro that will surround its argument with quotes


#define MyMacro(x)  "x"

// example:
// in the source file i will write:
a = MyMacro(abc);

//and the compiler will translate this to:

a = "abc"


is this possible in some way ?

TimoVJL

#include <stdio.h>

#define TEST(x) "\""#x"\""

int main(int argc, char **argv)
{
printf(TEST(Hello));
return 0;
}

May the source be with you

whatsup

thank you very very much sir.
it works!

CommonTater

Interesting... but wouldn't it be easier to just type in the " marks?