c语言中枚举类型
1、
#include <stdio.h> enum animal {Dog, Cat, Monkey, Invalid}; void dog(void) { puts("wang wang\n"); } void cat(void) { puts("miao miao\n"); } void monkey(void) { puts("ji ji\n"); } enum animal select(void) { enum animal tmp; do { puts("0: dog 1: cat 2: monkey 3: over!"); printf("tmp = "); scanf("%d", &tmp); } while(tmp < Dog || tmp > Invalid); return tmp; } int main(void) { enum animal selected; do { switch(selected = select()) { case Dog : dog(); break; case Cat : cat(); break; case Monkey : monkey(); break; } } while(selected != Invalid); return 0; }