Pelles C forum

C language => Beginner questions => Topic started by: whatsup on January 12, 2011, 10:16:05 PM

Title: is this possible with macros ?
Post by: whatsup on January 12, 2011, 10:16:05 PM
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 ?
Title: Re: is this possible with macros ?
Post by: TimoVJL on January 12, 2011, 10:35:58 PM
#include <stdio.h>

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

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

Title: Re: is this possible with macros ?
Post by: whatsup on January 13, 2011, 12:29:44 AM
thank you very very much sir.
it works!
Title: Re: is this possible with macros ?
Post by: CommonTater on January 13, 2011, 03:58:23 AM
Interesting... but wouldn't it be easier to just type in the " marks?