I want to convert a string to enum number. below code is what I want to do.
#define SELECT_DAY(s) s
enum sched {MON, TUE, WED};
int main(void)
{
char *str = "TUE";
printf("%d\n", SELECT_DAY(str));
return 0;
}
Just you can see, str has "TUE" string's pointer. So, I thought that printf function will print out number 1. But, It printed out string's address.
printf("%d\n", TUE);
above code is what I expected. Can't the predecessor handle this operation ? I know that the way to convert a string to enum in C# can be possible. In C, is there no way to convert a string to enum number ?