搜索论坛发现没有使用这种方式的多级菜单,为啥啊?
程序代码:
/* Note:Your choice is C IDE */ #include "stdio.h" unsigned char tt,key; void (*kfp)(); void menuf1() { printf("(选项1) 被选中\n\n\n"); printf("选项2\n"); printf("nop\n\n");} void menuf2() { printf("选项1 \n\n\n"); printf("(选项2) 被选中\n"); printf("nop\n\n");} void menuf3() { printf("\n\n\n执行动作2\n\n"); } void menuf4() { printf("\n\n\n执行动作1\n\n"); } typedef struct { unsigned char biaohao; unsigned char up; //输入1时对应up选择的标号 unsigned char down; //输入2时对应down选择的标号 unsigned char ok; //输入3时对应ok选择的标号 unsigned char back; //返回主菜单 void (*fun)(); } Menustruct; Menustruct Menu[4]={ {0,1,1,3,0,*menuf1},{1,0,0,2,0,*menuf2},{2,0,0,0,0,*menuf3},{2,0,0,0,0,*menuf4} }; unsigned char tt; void main() {key=Menu[0].biaohao; //初始化显示 kfp=Menu[key].fun; (*kfp)(); while(1){ scanf("%d",&tt); //输入1到4 switch(tt){ case 1: key=Menu[key].up; break; case 2: key=Menu[key].down; break; case 3: key=Menu[key].ok; break; case 4: key=Menu[key].back; break; return ; break; } kfp=Menu[key].fun; (*kfp)(); }}