#include #include #include #define NMAX 4 //学院每个项目最多4人 #define MAX 3 //个人最多三项 #define PEOPLE_MAX 6 //参赛人数得分以6为分界线 struct baoming { char number[12]; char school[15]; char name[12]; char sex[10]; char sport1[10]; char sport2[10]; char sport3[10]; }; void sign(struct baoming com,FILE *fp1,char d[]) { printf("\t请输入您的学号:\n"); scanf("%s",com.number); printf("\n请输入您的姓名"); scanf("%s",com.name); char a[]={"男"}; char b[]={"女"}; printf("\t请输入您的性别\n"); printf("\t1.男 2.女"); int sex1; scanf("%d",&sex1); if(sex1==1) { strcpy(com.sex,a); printf("男生的项目有:"); printf("1.标枪 2.跳高 3.100米 4.400米 5.1000米 6.5000米 7.跳远"); printf("\n请输入您要报名的项目,没有填无"); scanf("%s",com.sport1); printf("请再次输入"); scanf("%s",com.sport2); printf("请再次输入"); scanf("%s",com.sport3); fprintf(fp1,"%s %s %s %s %s %s %s\n ",com.number,d,com.name,com.sex,com.sport1,com.sport2,com.sport3); } else { strcpy(com.sex,b); printf("女生的项目有:"); printf("1.标枪 2.跳高 3.100米 4.400米 5.1000米 6.5000米 7.跳远"); printf("\n请输入您要报名的项目,没有填无"); scanf("%s",com.sport1); printf("请再次输入"); scanf("%s",com.sport2); printf("请再次输入"); scanf("%s",com.sport3); fprintf(fp1,"%s %s %s %s %s %s %s\n",com.number,d,com.name,com.sex,com.sport1,com.sport2,com.sport3); } fclose(fp1); printf("再见"); } void sign_up() { printf("请选择学院:"); printf("1.计算机学院 2.电气学院"); printf("3.文新学院 4.机械学院"); printf("5.土木学院 6.经贸学院"); int choice; scanf("%d",&choice); switch(choice) { case 1: { FILE *fp; char a[]="计算机学院"; struct baoming stu; fp=fopen("computer.txt","a+"); if(fp==NULL) printf("打开文件失败!"); sign(stu,fp,a); break; } case 2: { FILE *fp; char b[]="电气学院"; struct baoming stu; fp=fopen("dianqi.txt","a+"); if(fp==NULL) printf("打开文件失败!"); sign(stu,fp,b); break; } case 3: { FILE *fp; char c[]="文新学院"; struct baoming stu; fp=fopen("wenxin.txt","a+"); if(fp==NULL) printf("打开文件失败!"); sign(stu,fp,c); break; } case 4: { FILE *fp; char d[]="机械学院"; struct baoming stu; fp=fopen("jixie.txt","a+"); if(fp==NULL) printf("打开文件失败!"); sign(stu,fp,d); break; } case 5: { FILE *fp; char e[]="土木学院"; struct baoming stu; fp=fopen("tumu.txt","a+"); if(fp==NULL) printf("打开文件失败!"); sign(stu,fp,e); break; } case 6: { FILE *fp; char f[]="经贸学院"; struct baoming stu; fp=fopen("jingmao.txt","a+"); if(fp==NULL) printf("打开文件失败!"); sign(stu,fp,f); break; } } } void chaxun(struct baoming stu,FILE *fp1) { char numbers[12]; int flag=0; printf("\t请输入要查询的学号"); scanf("%s",numbers); while(!feof(fp1)&&flag==0) { fscanf(fp1,"%s%s%s%s%s%s%s%s",&stu.number,stu.school,stu.name,stu.sex,stu.sport1,stu.sport2,stu.sport3); if(strncmp(numbers,stu.number,11)==0) { printf("%s %s %s %s %s %s %s",stu.number,stu.name,stu.sex,stu.sport1,stu.sport2,stu.sport3); flag=1; printf("\t查询成功"); } } fclose(fp1); } void bmchaxun() { int x; printf("请选择您的学院"); printf("1.计算机学院 2.电气学院"); printf("3.文新学院 4.外国语学院"); printf("5.土木学院 6.经贸学院"); scanf("%d",&x); switch(x) { case 1: { struct baoming com; FILE *fp=fopen("computer.txt","r"); if(fp==NULL) { printf("文件打开失败!"); } chaxun(com,fp); break; } case 2: { struct baoming com; FILE *fp=fopen("dianqi.txt","r"); if(fp==NULL) { printf("文件打开失败!"); } chaxun(com,fp); break; } case 3: { struct baoming com; FILE *fp=fopen("wenxin.txt","r"); if(fp==NULL) { printf("文件打开失败!"); } chaxun(com,fp); break; } case 4: { struct baoming com; FILE *fp=fopen("jixie.txt","r"); if(fp==NULL) { printf("文件打开失败!"); } chaxun(com,fp); break; } case 5: { struct baoming com; FILE *fp=fopen("tumu.txt","r"); if(fp==NULL) { printf("文件打开失败!"); } chaxun(com,fp); break; } case 6: { struct baoming com; FILE *fp=fopen("jingmao.txt","r"); if(fp==NULL) { printf("文件打开失败!"); } chaxun(com,fp); break; } } } struct jianlu { char number[12]; char school[15]; char name[10]; char sex[5]; char sport[10]; }; void xie_ru(struct baoming stu,FILE *fp,FILE *fp1,char a[]) { long last,h; fseek(fp1,0L,SEEK_END); last=ftell(fp1); rewind(fp1); while((h=ftell(fp1))PEOPLE_MAX) { while(h=ftell(fp):"); scanf("%d",&choice1); switch(choice1) { case 1: system("cls"); sign_up(); break; case 2: system("cls"); bmchaxun(); break; case 3: system("cls"); jianlu(); break; case 4: system("cls"); dengji(); break; case 5: system("cls"); cjcx(); break; case 6: system("cls"); paixu(); break; } }while(0); } int main(void) { system("color 3f"); menu(); }