I’m wondering if it’s possible to paste a character as a token in C at runtime. Something like,
a = OPERATION(3, 4, '+')
will be processed to,
a = 3 + 4
Is there a way to do this?
Edit: I wanted to add some more information. Obviously this can’t be done with the preprocessor. I’m wondering if there’s a short way to do,
int i;
char sign[] = "+-*/";
for (i = 0; i < 4; i++)
printf("%d\n", OPERATION(3, 5, sign[i]));
I know we can create a function as,
int OPERATION(int a, int b, char c);
But this is not what I’m asking.
How about this:
However, as delnan notes below, you would have to modify your call to: