Printing space with a macro and # operator in C

Viewed 483

I was working with macros and wrote one like this:

#define STR(name) #name

I meant STR() to stringise whatever that was given to it as argument and it seemed to be working.

printf( STR(Hello) )

gave the output as expected:

Hello

So did

printf( STR(Hello world) );
printf( STR(String) STR(ise) );

which gave

Hello world
Stringise

But when I tried to use STR() to print only a space, it just didn’t work.

printf( STR(Hello) STR( ) STR(World) ); //There’s a space between the parenthesis of the second STR

Gave the output:

HelloWorld

Here the STR( ) is ignored.

Why is this? Is there a way around it using while still sticking to macros with only a space as argument?

I was just wondering if this was possible.

1 Answers
Related