资源描述:
《链表编写学生信息管理系统》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include#include#include#inelude#defineNULL0structstudentcharxuehao[10];charname[15J;charxingbie[6];intnianling;intdianhua;charlicence[20];charaddress[40J;charyouxiang[100];structstudent*next;};structstudent*creat()//创建链表{structstudent*p,*head,*end;head=p=end
2、=(structstudent*)malloc(sizeof(structstudent));//创建一个节点printf("====请输入学生信息二===");printfC请输入学生学号:”);scanf("%s",p->xuehao);while(strcmp(p->xuehao,M0M)!=0){end=p;printf(H姓名:“);scanf(”%s”,p->name);printf(”性别:“);scanf(M%s",p->xingbie);printf("年龄:“);scanf(H%d'&p->nianling);printf(M电话:“);scanf(n%d'&
3、p->dianhua);printf(H证件号:“);scanf("%s",p->licence);printf(”家庭住址:“);scanf(H%s'*,p->address);printf(n邮箱:“);scanf('*%s",p->youxiang);p=(structstudent*)malloc(sizeof(structstudent));end->next=p;//end=p;printfC*请输入学生学号:“);scanf(H%sH,p->xuehao);}end->next=NULL;returnhead;voidsave(structstudent*head)//保存
4、链表为磁盘文件{FILE*fp;structstudent*p;charfilename[20];intch;printf(M请输入要保存的文件名:”);scanf("%s",filename);if((fp=fopen(filename,nrn))!=NULL){printfC*该文件已经存在,是否覆盖?M);printf(Ml>覆盖.2、不覆盖“);scanf(”%d“,&ch);if(ch!=l){printfC*请重新输入要保存的文件名:”);scanf("%s",filename);}}if((fjp=fopen(filename,',w"))==NULL){print
5、fC*创建文件失败!”);return;//exit(0);正常退出,执行后显示pressanykeytocontinue;}//getchar();p=head;while(p!=NULL){fprintf(fp,"%s",p->xuehao);fprintf(fp/'%s",p->name);fprintf(fp/'%s",p->xingbie);fprintf(fp/'%d'p->nianling);fprintf(fp,"%d",p・>dianhua);fpriiHf(fpr%s”,p・>licence);fprintf(fp,"%s",p->a
6、ddress);fprintf(fp/'%s",p->youxiang);p=p->next;}fputs(noverM,fp);printf(H文件保存成功!“);〃getchar();fclose(fp);}voidoutput(structstudent*head)〃输出链表{structstudent*p;p=head;if(p=NULL){printf(”未创建任何记录!”);getchar();return;//head;}while(p!=NULL)//do{printf(M学号:%s'p->xuehao);printf(H姓名:%sM,p->name);
7、printf(u性别:%sn,p->xingbie);printf("年龄:%d",p->nianling);printf("电话:%d",p->dianhua);printf("证件号:%s",p->Iicence);printf(u家庭地址:%sM,p->address);printf(uyouxiang:%s",p->youxiang);p=p->next;}//while(p!=NULL);get