1 //运行文件前在D盘建一个program文件夹 2 #include3 #include 4 #include 5 #include 6 #include 7 struct student 8 { 9 int num; 10 char name[50]; 11 char sex[20]; 12 int age; 13 char address[50]; 14 char xiyuan[20]; 15 char zhuanye[20]; 16 }stu[1000000]; 17 int cmp(student a,student b) 18 { 19 return a.num 增加 或 0->结束增加 : "); 86 scanf("%d",&true2); 87 getchar(); 88 if(!true2) break; 89 printf("\n 请依次输入增加的每个学生的学籍信息\n"); 90 printf("\n 学号:");scanf("%d",&stu[0].num);getchar(); 91 printf(" 姓名:");scanf("%s",stu[0].name);getchar(); 92 printf(" 性别:");scanf("%s",stu[0].sex);getchar(); 93 printf(" 年龄:");scanf("%d",&stu[0].age);getchar(); 94 printf(" 籍贯:");scanf("%s",stu[0].address);getchar(); 95 printf(" 系院:");scanf("%s",stu[0].xiyuan);getchar(); 96 printf(" 专业:");scanf("%s",stu[0].zhuanye);getchar(); 97 fprintf(fp,"\t%d\t%s\t%s\t%d\t%s\t%s\t%s\n",stu[0].num,stu[0].name,stu[0].sex,stu[0].age,stu[0].address,stu[0].xiyuan,stu[0].zhuanye); 98 } 99 fclose(fp);100 system("pause\n");101 }102 void modify()/*修改学生学籍信息*/103 {104 system("cls");105 int i=0,j,n;106 FILE *fp;107 if((fp=fopen("d:\\program\\student.txt","r"))==NULL)108 {109 printf("\n打开文件失败!!!\n");110 getch();111 exit(1);112 }113 memset(stu,0,sizeof(stu));114 while(fscanf(fp,"%d",&stu[i].num)!=EOF)115 {116 fscanf(fp,"%s%s%d%s%s%s",stu[i].name,stu[i].sex,&stu[i].age,stu[i].address,stu[i].xiyuan,stu[i].zhuanye);117 i++;118 }119 fclose(fp);120 while(1)121 {122 123 printf("\n ※※※※※※※※※※※※※※※※※※※※※※※※\n");124 printf(" ※※※※※※※※※※※※※※※※※※※※※※※※\n");125 printf(" ※※ ※※\n");126 printf(" ※※ 1:按照学号修改学生学籍: ※※\n");127 printf(" ※※ ※※\n");128 printf(" ※※ 2:按照姓名修改学生学籍: ※※\n");129 printf(" ※※ ※※\n");130 printf(" ※※ 3:返回主菜单 ※※\n");131 printf(" ※※ ※※\n");132 printf(" ※※※※※※※※※※※※※※※※※※※※※※※※\n");133 printf(" ※※※※※※※※※※※※※※※※※※※※※※※※\n");134 printf("\n输入数据,请选择(1—3):");135 scanf("%d",&n);136 while(n<1||n>3)137 {138 printf("输入错误,请重新输入!!\n");139 scanf("%d",&n);140 }141 if(n==3) break;142 if(n==1)143 {144 int num,flag=0;145 printf("\n请输入学号:");146 scanf("%d",&num);147 for(j=0;j 3)239 {240 printf(" 输入错误,请重新输入!!\n");241 scanf("%d",&n);242 }243 if(n==3) break;244 if(n==1)245 {246 int num,flag=0;247 printf("\n请输入学号:");248 scanf("%d",&num);249 for(j=0;j 3)330 {331 printf(" 输入错误,请重新输入!!\n");332 scanf("%d",&n);333 }334 if(n==3) break;335 if(n==1)336 {337 int num,flag=0;338 printf("\n 请输入学号: ");339 scanf("%d",&num);340 for(j=0;j 1) printf("\n 请重新输入账号和密码:\n");438 printf("\n 请输入用户名: ");scanf("%s",user1);439 printf("\n 请输入密码: ");scanf("%s",password1);440 if(!strcmp(user1,user)&&!strcmp(password1,password))441 break;442 else443 {444 printf("\n 账号或密码错误!!!\n");445 Sleep(1000);446 447 }448 system("cls");449 }450 }451 void password()/*修改密码*/452 {453 char user1[50],password1[50];454 FILE *fp;455 if((fp=fopen("d:\\program\\password.txt","w"))==NULL)456 {457 printf("\n打开文件失败!!!\n");458 getch();459 exit(1);460 }461 printf("\n 请输入新的用户名: ");scanf("%s",user1);462 printf("\n 请输入新的密码: ");scanf("%s",password1);463 fprintf(fp,"%s%c",user1,'\n');464 fprintf(fp,"%s%c",password1,' ');465 fclose(fp);466 printf("\n密码已修改!!!\n\n");467 system("pause\n");468 }469 void exit()470 {471 exit(0);472 }473 int main()474 {475 int n;476 system("color 4e");477 newboot ();478 while(1)479 {480 menu();481 printf("请输入1~8操作命令,选择功能:");482 scanf("%d",&n);483 while(n>8||n<0)484 {485 printf("输入错误!!请重新输入n\n");486 scanf("%d",&n);487 }488 switch(n)489 {490 case 1 :newbuild();break;491 case 2 :add();break;492 case 3 :modify();break;493 case 4 :del();break;494 case 5 :search();break;495 case 6 :Browse();break;496 case 7 :exit();break;497 case 8 :password();break;498 }499 }500 }