C query

Discussion in 'C' started by shyam_oec, Nov 26, 2007.

  1. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    i want to get the print of enumuration constants that has been defined in current enumeration in C language.how?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Moved to C-C++ forum.
     
  3. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    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" }
    };
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice