C query

Contributor
26Nov2007,23:25   #1
shyam_oec's Avatar
i want to get the print of enumuration constants that has been defined in current enumeration in C language.how?
Go4Expert Founder
26Nov2007,23:27   #2
shabbir's Avatar
Moved to C-C++ forum.
Ambitious contributor
27Nov2007,04:31   #3
Salem's Avatar
The short answer is "you can't", not in standard C.

Given
Code:
enum colours { red, green, blue };
there is no quick and easy way of getting the system to print say "red".

One way is to define a lookup table, such as
Code:
struct {
  enum colours;
  char *word;
} table[] = {
  { red, "red" },
  { green, "green" },
  { blue, "blue" }
};