Are you seeking to change the integer
enum value into a string that matches the name assigned to that value in the
enum definition?
The C compiler does not provide any way to do that. You, however, have the option of creating and managing your own lookup table that associates a string with each value. It will be up to you to make sure that the strings in the table actually match the names in the
enum definition. For instance, something like this:
- const struct {
-
enum Color value;
-
const char *name;
-
} table[] = {
-
...
-
{ RED, "RED" },
-
...
-
};
-
The following lookup table mistake does not provoke a compiler warning: