C query

shyam_oec's Avatar, Join Date: Nov 2007
i want to get the print of enumuration constants that has been defined in current enumeration in C language.how?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to C-C++ forum.
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
The short answer is "you can't", not in standard C.

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
struct {
  enum colours;
  char *word;
} table[] = {
  { red, "red" },
  { green, "green" },
  { blue, "blue" }