Hello,
I need to convert an enumeration member (its value, not the identifier) to a string. I have tried the following, which works for a MACRO (TYPE_A), but not for an enum value (typeA). This is a little bit strange in my opinion.
Do you have any idea how to do this?
#define _tostr(a) #a
#define tostr(a) _tostr(a)
typedef enum _SPECIAL_FOLDER_ID {
typeA = 3,
typeB = 4,
} SPECIAL_FOLDER_ID;
#define TYPE_A 3
int main() {
//this is working, but the information is a macro (TYPE_A)
printf("The string is " tostr(TYPE_A) ".\n");
//this is not working for typeA (defined in an enumeration)
printf("The string is " tostr(typeA) ".\n");
return 0;
}
The output is:
The string is 3. The string is typeA.
I need to modify the code in some way so that the second line of the output will be "The string is 3."
Thanks!
PS: I do not want to print the value using printf. I need a static string containing that value. I only use printf to test the result...