Hey take a look at the code:
#define SUFFIX(n) (switch(n) \
{ \
case 1: printf("st\n"); \
break; \
\
case 2: printf("nd\n"); \
break; \
\
case 3: printf("rd\n"); \
break; \
} \
)
calling the above macro in main:
int main()
{
printf("%s", suffix(1));
}
But when I call this I get a error message:
expected expression before switch
But what expression am I missing?
What you’re trying to do won’t work.
switchis a statement butprintfrequires an expression.Option 1:
Remove the brackets
()from your#defineand simply saySUFFIX(1)without theprintf.Option 2:
Option 3 and 4:
Make one of the above a function. The first returns
void, the second returnschar *.