I wanted to know if there was any other way to print enum names. Such as this one which I was trying,
typedef enum {
Apple,
Berry,
Grapes,
} FruitType;
And this enum printing function
void printFruitType(FruitType type)
{
switch(type)
{
case Apple: printf("Apple"); break;
case Berry: printf("Berry"); break;
case Grapes: printf("Grapes"); break;
}
}
But this seems laborious, each time I need to write the same code still I need to change the printf
statement to print the proper value.
Moreover, the FruitType
enum can grow big, so writing a enum printing function wouldn't be a great way to print enum name as a string.
So, how can I tackle this enum printing problem.