内容发布更新时间 : 2024/12/26 22:38:08星期一 下面是文章的全部内容请认真阅读。
strcpy(s[j].email,u[j].email);
strcpy(s[j].graduateschool,u[j].graduateschool); fclose(fp1); } } else {printf(\选择错误!!系统自动返回\\n\ }
void paixu(int n){ /*此为排序函数*/ int j,k;
struct students u[100],v[100]; FILE *fp1;
fp1=fopen(\TION.txt\
for(k=0;k strcpy(u[k].name,s[k].name); u[k].age=s[k].age; strcpy(u[k].sex,s[k].sex); strcpy(u[k].birthdate,s[k].birthdate); strcpy(u[k].address,s[k].address); strcpy(u[k].phonenumber,s[k].phonenumber); strcpy(u[k].email,s[k].email); } strcpy(u[k].graduateschool,s[k].graduateschool); } fclose(fp1); for(j=0;j for(k=0;k if(u[k].num>u[k+1].num){ v[k].num=u[k].num; u[k].num=u[k+1].num; u[k+1].num=v[k].num; strcpy(v[k].name,u[k].name); strcpy(u[k].name,u[k+1].name); strcpy(u[k+1].name,v[k].name); v[k].age=u[k].age; u[k].age=u[k+1].age; u[k+1].age=v[k].age; strcpy(v[k].sex,u[k].sex); strcpy(u[k].sex,u[k+1].sex); strcpy(u[k+1].sex,v[k].sex); strcpy(v[k].birthdate,u[k].birthdate); strcpy(u[k].birthdate,u[k+1].birthdate); strcpy(u[k+1].birthdate,v[k].birthdate); strcpy(v[k].address,u[k].address); strcpy(u[k].address,u[k+1].address); strcpy(u[k+1].address,v[k].address); strcpy(v[k].phonenumber,u[k].phonenumber); strcpy(u[k].phonenumber,u[k+1].phonenumber); strcpy(u[k+1].phonenumber,v[k].phonenumber); strcpy(v[k].email,u[k].email); strcpy(u[k].email,u[k+1].email); strcpy(u[k+1].email,v[k].email); strcpy(v[k].graduateschool,u[k].graduateschool); strcpy(u[k].graduateschool,u[k+1].graduateschool); strcpy(u[k+1].graduateschool,v[k].graduateschool); } } } for(k=0;k k ,u[k].num,u[k].name,u[k].age,u[k].sex,u[k].birthdate,u[k].address,u[k].phonenumber,u[k].email,u[k].graduateschool); } fclose(fp1); } void changes(){ /*此处为修改函数*/ FILE *fp1,*fp2; long number; int j,flag=0; int choice; if((fp1=fopen(\TION.txt\ printf(\学生信息没有被录入,按任意键返回:\\n\ } fp1=fopen(\TION.txt\ fp2=fopen(\ printf(\请输入学号\\n\ scanf(\ for(j=0;fread(&s[j],sizeof(struct students),1,fp1)!=0;j++){ if(s[j].num==number){ /*判断该学生是否出在*/ printf(\学生的信息如下:\\n\ print(j); getchar(); return; printf(\ printf(\ \\n\printf(\ 1.修改学生姓名\\n\printf(\ 2.修改学生年龄\\n\printf(\ 3.修改学生性别\\n\ printf(\ 4.修改学生出生日期\\n\ printf(\ 5.修改学生家庭地址\\n\ printf(\ 6.修改学生电话号码\\n\ printf(\ 7.修改学生电子邮件\\n\ printf(\ 8.修改学生毕业学校\\n\ /*列出修改菜单*/ printf(\ scanf(\ switch(choice){ case 1:{ printf(\请输入新姓名\\n\ scanf(\ fwrite(&s[j],sizeof(struct students),1,fp2); }break; case 2:{ printf(\请输入新年龄\\n\ scanf(\ fwrite(&s[j],sizeof(struct students),1,fp2); }break; case 3:{ printf(\请输入新性别\\n\ scanf(\ fwrite(&s[j],sizeof(struct students),1,fp2); }break; case '4':{ printf(\请输入新出生日期\\n\ scanf(\ fwrite(&s[j],sizeof(struct students),1,fp2); }break; case '5':{ printf(\请输入新家庭地址\\n\ scanf(\ }break; case 6:{ printf(\请输入新电话号码\\n\ fwrite(&s[j],sizeof(struct students),1,fp2); scanf(\ fwrite(&s[j],sizeof(struct students),1,fp2); }break; case 7:{ printf(\请输入新电子邮件\\n\ scanf(\ fwrite(&s[j],sizeof(struct students),1,fp2); }break; case 8:{ printf(\请输入新毕业学校\\n\ scanf(\ fwrite(&s[j],sizeof(struct students),1,fp2); }break; default: printf(\选择错误!!系统自动返回\\n\ fwrite(&s[j],sizeof(struct students),1,fp2); break; } flag=1; /*第一个if*/ } else fwrite(&s[j],sizeof(struct students),1,fp2); /*for循环*/} if(flag==0) printf(\学生不存在!!系统自动返回\\n\ fclose(fp1); fclose(fp2); /*修改完成,信息重新写入文本*/ } fp1=fopen(\TION.txt\ for(j=0;fread(&s[j],sizeof(struct students),1,fp2)!=0;j++){ fwrite(&s[j],sizeof(struct students),1,fp1); } fp2=fopen(\ fclose(fp1); fclose(fp2); 参考文献: 《C语言程序设计基础》 李丽娟、牛莉主编 铁道出版社 《C语言程序设计》 黄迪明、胡德昆主编 电子科技大学出版社 《C程序设计》 谭浩强主编 清华大学出版社