Map enum to char array : Enum « Data Type « C / ANSI-C






Map enum to char array


#include <stdio.h>

enum status{
  one,
  two,
  three,
  four,
  five
};

char *stats[] = {
  "1",
  "2",
  "3",
  "4",
  "5"
};

#define NUMBER_OF_INPUTS ( sizeof ( stats ) / sizeof ( stats[0]))

int main() {
  enum status;
  int name;
  

  printf ( "Number of Inputs is: %d\n", NUMBER_OF_INPUTS );
  for ( name = one; name < NUMBER_OF_INPUTS; name++) {
    printf ( "\n%s", stats[ name ] );
  }
  
  printf ( "\n\n" );
}


           
       








Related examples in the same category

1.Map enum to char and output with for loop
2.Define and use enum
3.Reference enum value by int
4.Map enum to string array