Mega Code Archive
 
 
    
Reference enum value by int
#include 
#include 
#include 
enum animal {cat, dog, lion, tiger} j;
int main(void)
{
 printf("Press a key to select animal: ");
 /* generate a new random number */
 while(!kbhit()) 
 rand();
 getch(); /* read and discard character */
 j = rand() % 4;
 switch(j) {
 case cat: printf("cat");
 break;
 case dog: printf("dog");
 break;
 case lion: printf("lion");
 break;
 case tiger: printf("tiger");
 }
 return 0;
}