Thread: enum

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    96

    enum

    i have a program help iam not sure how to use enum can someone give me and example. i have read through my book but i still dont understand. here is my code. How can i access it

    Code:
    enum days
    {
        sunday,monday,saturday
    };

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Given the enum declaration you can create variables of that type, as in
    Code:
    enum days var;  /* var can assume any 3 values listed in the enum tag declaration */

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    MD, USA
    Posts
    71
    What?
    enums are kinda like an easy way to create #defines keywords with values automatically assigned in a sequence which can be specified in a variety of ways. The values must be integer constants like 2 or '2' .
    Code:
    #include <stdio.h>      /*  enum-2.c  */
    
    int main(void)
    {                                                        /* assigned values */
      /*enum days{ mon, tue, wed, thu, fri, sat, sun};            0 1 2 3 4 5 6 */
      enum days{ mon = 1, tue, wed, thu, fri, sat, sun  };     /* 1 2 3 4 5 6 7 */
    
      int i = 3;
     
      printf("\n mon= %d  tue= %d  wed= %d  thu= %d  fri= %d  sat= %d  sun= %d \n",
               mon, tue, wed, thu, fri, sat, sun );
    
      if (i == wed)
        printf("It's wednesday \n");
    
      return 0;
    }
    
    /******  OUTPUT:  **************/
    ~>  gcc -Wall -W -pedantic enum-2.c  -o  enum-2
    ~>  ./enum-2
    
     mon= 1  tue= 2  wed= 3  thu= 4  fri= 5  sat= 6  sun= 7 
    It's wednesday
    Last edited by HowardL; 03-30-2010 at 12:21 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. enum [tag] [: type] Is this non-standard?
    By HyperShadow in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2007, 10:29 PM
  2. enum switchcase and windows message q
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2006, 01:16 PM
  3. Conflicting enum issue
    By 7force in forum C Programming
    Replies: 1
    Last Post: 07-05-2006, 03:51 AM
  4. Switch case and enum help
    By SomeCrazyGuy in forum C++ Programming
    Replies: 9
    Last Post: 04-21-2005, 08:53 PM
  5. enum
    By JerryL in forum C++ Programming
    Replies: 5
    Last Post: 02-25-2004, 05:45 PM