1 /*----------------------------- 2 enum.c -- 使用枚举类型的值 3 -----------------------------*/ 4 5 #include <stdio.h> 6 #include <string.h> 7 //#include <stdbool.h> //C99特性 8 9 #define LEN 30 10 11 char* s_gets(char *st, int n); 12 13 enum spectrum {red, orange, yellow, green, blue, violet}; 14 const char *colors[] = {"red", "orange", "yellow", "green", "blue", "violet"}; 15 16 int main() 17 { 18 char choice[LEN]; 19 int color; 20 bool color_is_found = false; 21 22 puts("Enter a color (empty line to quit):"); 23 24 while (s_gets(choice, LEN) != NULL && choice[0] != '