发布网友 发布时间:2023-08-16 03:37
共1个回答
热心网友 时间:2024-11-29 00:22
#include<stdio.h>#include<string.h>void menu();//输出主菜单void create();//1.学生名单输入void sign();//2.跑步签到void search();//3.查询void save();//保存int i,n;struct Student { char name[20]; char num[20]; int time; };struct Student stu[4];int main(){ do{ menu(); scanf("%d",&n); switch(n) { case 1: printf("1.学生名单输入\n");create();break; case 2: printf("2.跑步签到!\n");sign();break; case 3: printf("3.查询!\n");search();break; case 0: printf("0.退出系统!\n");break; default:printf("您输入的选项不存在,请重新确认后再次输入!\n"); } } while(n>0); return 0;}void menu(){ printf("欢迎进入跑步签到系统\n"); printf("1.学生名单输入\n"); printf("2.跑步签到\n"); printf("3.查询\n"); printf("0.退出系统\n"); printf("请输入要选择的菜单:\n");}void save(){ FILE *fp; fp = fopen("myfile.dat","a+"); if(fp == NULL ) printf("Cannot open file\n"); fwrite(stu,sizeof(struct Student),4,fp); fclose(fp);}void create(){ int u; for(u=0;u<4;u++) { printf("请输入学生姓名:"); scanf("%s",stu[u].name); printf("请输入学号:"); scanf("%s",stu[u].num); printf("请输入次数:"); scanf("%d",&stu[u].time); } save();}void sign(){ int w; char x[20]; printf("请输入打卡的学生的学号:"); scanf("%s",&x); for(w=0;w<4;w++) { if(strcmp(stu[w].num,x)==0) break; } stu[w].time=stu[w].time+1; printf("签到成功\n"); save();}void search(){ int w; char x[20]; printf("请输入你想查找的学生的学号:"); scanf("%s",&x); for(w=0;w<4;w++) { if(strcmp(stu[w].num,x)==0) break; } printf("姓名\t学号\t次数\t\n"); printf("%s\t",stu[w].name); printf("%s\t",stu[w].num); printf("%d\n",stu[w].time);}bug已经修改好了fp=open中根据需要修改w或者a追问我要的身份证归属地查询,这个我看不懂呀