struct staff char unit[60] char name[201 char sex[20 Int age; int height int weight
struct staff { char unit[60]; char name[20]; char sex[20]; int age; int height; int weight; };
冷 void main0 struct staff sta[Max /定义结构数组* FILE fI 结构数组,即可输入的最大职工数, 最大值为声明中预定义的Max*/ ints;/设置变量,以用于用户输入信息的接收, 并将其作为转向函数的参数* int n=0 /整型变量* char choice char pass[8: int flag=0; int w=3 char menu 20]={添加""显示""按姓名排序""按身高 排序","按体重排序",检索","修改""删除","存盘","返回" 令 char openfile[10;
❖ void main() ❖ { ❖ struct staff sta[Max]; /*定义结构数组*/ ❖ FILE *fp; /*结构数组,即可输入的最大职工数, 最大值为声明中预定义的Max*/ ❖ int s; /*设置变量,以用于用户输入信息的接收, 并将其作为转向函数的参数*/ ❖ int n=0; /*整型变量*/ ❖ char choice; ❖ char pass[8]; ❖ int flag=0; ❖ int w=3; ❖ char menu[][20]={"添加","显示","按姓名排序","按身高 排序","按体重排序","检索","修改","删除","存盘","返回"}; ❖ char openfile[10];
dol printi("请输入管理员密码:η"); scanf(%s", pass) if(!strcmp(pass, password)) pf rinf("PASSin\n) g break dse printi"密码错误,请重新输入:n
do{ printf("请输入管理员密码:\n"); scanf("%s",pass); if(!strcmp(pass,password)) { printf("PASS\n\n\n"); flag = 1; break; } else { printf("密码错误,请重新输入:\n"); w--; } }
while(w>0) if(flag) printf("你已连续三次输入错误,请确认后再使用本系统, 谢谢!n"); exit(O) system("cls");/用 system调用dos命令,清屏
while(w>0); if(!flag) { printf("你已连续三次输入错误,请确认后再使用本系统, 谢谢!\n"); exit(0); } system("cls");/*用system调用dos命令,清屏*/
printf("n打开已有的文件'staf3dat"?y/n)") scant(" %s",openfile if(strcmp(openfile, y)==NULI if((fp=fopen( d: staff 3.dat", TD==NULL printi"不能打开文件!n"); exit(O)
printf ("\n 打开已有的文件\"staff_3.dat\"?(y/n)"); scanf("%s",openfile); if((strcmp(openfile,"y")==NULL)) { if((fp=fopen("d:\\staff_3.dat","r"))==NULL) { printf("不能打开文件!\n"); exit(0); }