I have a constant defined:
#define MAX_STR_LEN 100
I am trying to do this:
scanf("%" MAX_STR_LEN "s", p_buf);
But of course that doesn't work.
What preprocessor trick can be use to convert the MAX_STR_LEN numerica into a string so I can use it in the above scanf call ? Basically:
scanf("%" XYZ(MAX_STR_LEN) "s", p_buf);
What should XYZ() be ?
Note: I can of course do "%100s" directly, but that defeats the purpose. I can also do #define MAX_STR_LEN_STR "100", but I am hoping for a more elegant solution.
#define f(x) #x
will preprocessf(foo)
into"foo"
– Mediate