资源描述:
《学生信息管理系统_c语言课程设计new》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、七、源代码�#include"stdio.h"#include"stdlib.h"#include"string.h"#include"conio.h"#defineNsizeof(structstud)//测结构体变量的大小//typedefstructstud{charnumber[20];charname[20];charsex[20];charcall[20];charQQ[20];charadd[20];structstud*next;}Elemsn;//为结构体命名//Elemsn*creatlink(void)//创建链表信息//{Elemsn*p1,*p2,*
2、head;//p1为前驱,p2为后继//inti=1;charchoice;head=p2=(Elemsn*)malloc(N);head->next=NULL;choice='y';for(i=1;choice=='y'
3、
4、choice=='Y';i++){p1=(Elemsn*)malloc(N);printf("*******************************************************************************");printf("请输入第%d个学生的信息:",i);printf("学号�");sca
5、nf("%s",p1->number);printf("姓名:");scanf("%s",p1->name);printf("性别:");scanf("%s",p1->sex);printf("电话:");scanf("%s",p1->call);printf("QQ:");scanf("%s",p1->QQ);printf("宿舍号:");scanf("%s",p1->add);p2->next=p1;p2=p1;printf("是否继续?(Y/N):");choice=getche();printf("");}p2->next=NULL;ret
6、urn(head);}voidsavelink(Elemsn*h)//保存链表信息//{Elemsn*p;FILE*fp;charfliename[20];printf("请输入你要保存的文件名�");scanf("%s",fliename);if((fp=fopen(fliename,"wt"))==NULL){printf("写文件出错�按任意键退出!");getche();exit(1);}for(p=h->next;p!=NULL;p=p->next)fprintf(fp,"%s%s%s%s%s%s",p->number,p->name,p->sex,p->c
7、all,p->QQ,p->add);//向文件中写入数据//printf("文件已成功保存�按任意键返回!");getche();fclose(fp);}Elemsn*readlink(void)//读出已保存文件的信息//{Elemsn*head,*p,*q;FILE*fp;charfilename[20];printf("请输入要打开的文件名:");scanf("%s",filename);if((fp=fopen(filename,"rt"))==NULL){printf("读文件出错�按任意键退出!");getche();exit(1);}head=q=(Elem
8、sn*)malloc(N);head->next=NULL;while(!feof(fp)){p=(Elemsn*)malloc(N);//建立新链表,并从文件中读出数据//fscanf(fp,"%s%s%s%s%s%s",p->number,p->name,p->sex,p->call,p->QQ,p->add);q->next=p;q=p;}q->next=NULL;fclose(fp);printf("文件信息已正确读出�按任意键返回!");getch();returnhead;}Elemsn*insert(Elemsn*head)//插入信息//{Elemsn*p
9、;p=(Elemsn*)malloc(N);printf("请输入要插入学生的信息:");printf("学号�");scanf("%s",p->number);printf("姓名:");scanf("%s",p->name);printf("性别:");scanf("%s",p->sex);printf("电话:");scanf("%s",p->call);printf("QQ:");scanf("%s",p->QQ);printf("宿舍号:");scanf("%s