版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include<stdio.h>#include<dos.h>#define N sizeof(struct STH)#define GESHI H%-1 Old%"0s%-5s%-4d/%-2d/%-4d%-12s%-12s%snB#define PRINTF ”学号别级struct STH* readfilef);/* 声明”/ int insert(struct STH*);int n=O;struct dtint year;int month;int day;struct STHlong num;头"/char name9;性别 生 日系家
2、庭住址n"广全局变量/厂学号不能以0开char sex5;考试资料.struct dt birth;char xi20;char ban20;char add30;struct STH* next;*head;厂输人模快"/inpuLmessage()char ch;int flag=1;doif(insert(&head)!=O)n+;elseprintf('n有相同的的学号!");printfCn 是否抵续?(y/n)");getchar();scanf(B%cM,&ch);if(ch='y,|ch=,Y,)Pintf
3、('n 地续!“);getch();flag=1厂标志程序不给束*/elseflag=O;while(flag=1);save_message();printf(檢任意權缱续.);getch();/*insert()模tt*/广被输人和插人模挟所iBI用才/int insert(struct STH*h)struct STH *p,*pO;p=(struct STH*)malloc(N);printfCn请输入学号:);scanfC%ld",&p->num);printfCn请输人妳名:"); scanf("%s",p->na
4、me);printfCn i青输人11别:);getcharO;/*取走上一个留下来得'n' */scanf("%s,p->sex);printf(-n请输入生日(年月日,用回车隔开):眄;scanfC%d%d%dl,&p->birth.yearl&p->birth.monthf&p->birth.day);printfCn请聯入系别:");scanfC%sM,p->xi);printfCn 请输人 JS 级scanf(B%sM,p->ban);printfCn j青输人家庭住址门;scanf(&q
5、uot;%s,p->add);p->next二NULL;if(*h=NULL)*h=p;return 1;pO=*h;if(pO->num>p->num)p->next=pO;h=preturn 1;while(pO->next!=NULL&&pO->next->num<p->num)pO=pO->next;if(pO->next=NULL)pO->next=p;return 1;else if(pO->next->num=p->num)free(p);厂有相同数弼输人失败*/
6、return 0;elsep->next=pO->next;p0->next=p;return 1;厂读文件模快*/广读文件模快中曲建了 一个新的旌表,其返回值为新铢表的头IB it*/struct STH *readfile()FILE *fp;struct STH *p,*pO;char ch;int i;if(fp=fopenCSTH.txtVr")=NULL)printf(-n 不能读 ® 文件!nB);return NULL;广注意要该*/head=p=pO=(struct STH *)malloc(N);fscanf(fp,"%d
7、39;,&n);fscanf(fp,H%c-,&ch);厂为了使学号和信息个数分开加人一个'/' */fscanf(fp,M%ld%s%s%d%d%d%s%s%s",& p->num,p->name,p->sex,&p->birth.year,&p->birth.mont h,&p->birth.day,p->xi,p->ban,p->add);p->next=NULL;i=1;厂如果只有一个数时跳岀*/if(n!=1)dop=(struct STH *)mal
8、loc(N); fscanf(fp,%ld%s%s%d%d%d%s%s%s",& p->num,p->name,p->sex,&p->birth.year,&p->birth.month,&p->birth.day,p->xi,p->ban,p->add);pO->next=p;po=p;i+;while(i<n); pO->next=NULL;fclose(fp);return head;广插人模ST/insert_message() struct STH *p;int flag
9、=1;char ch;head=readfile();doif(insert(&head)!=O)n+;save_message();printf("H);广计数"/elseprintf('n添加失败!n有相同的的学号!“); save_message();getch();printfCn 是否址续?(y/n)");getchar();ch=getchar();if(ch='y'|ch=,Y,)pintf(、n 址续!“);flag=1厂标志程序不给束*/Ielseflag=O;while(flag=1);printf(An按任意權
10、继续.);getch();厂修改模JT/renew_message()struct STH *p;int i,flag=1;long num;p=head=readfile();if(head=NULL)printf(读文件有锲!");getch();elseprintf(-n请按输人要修改的学生的学号:");scanf('%ld",&num);for(i=0;i<n;i+)if(p->num=num)p->num=num;printf(An已找到i%ld号学生的信息!nH,num);printfCJg ft名为s要修改为:n:p
11、-name);scanfC%sM,p->name);printf("Jg 性别为 s 要修改为:n',p->sex);scanf(s:p->sex);printfC'lg生日为%d/%d/%d 要修改为:n",p->birth.year,p->birth.month,p->birth.day);scanf("%d%d%d,&p->birth.year,&p->birth.mo nth,&p->birth.day);printfr原系别为s要修改为:np->xi);s
12、canfC%s:p->xi);printf("原册级为s要修改为:n',p->ban);scanf(s:p->ban);printf(1l家庭住址为s要修改为:n",p->add);scanf('%sH,p->add);printf("你所更改后的信息为:nH);printf(PRINTF);printf(GESHI,p->num,p->name,p->sex,p->birth.year,p->birth.month,p->birth.day,p->xi,p->ban,p
13、->add);printf(-n 按任意SI退岀! nM);getch();flag=1;break;Ielsep=p->next;if(flag!=1)printfC*无此人信息! nn);elsesave_message();getch();厂K除模ST/delete_message()int flag;long num;char ch;struct STH*p,*pO;pO=p=head=readfile();if(head=NULL)printfC文件读取岀错!");getch();elseprintfC请输人要删除学生的学号:n");scanfC%ld
14、H,&num);if(pO->num=num)head=pO->next;free(pO);flag=1;n-;广学生数城一*/p=pO->next;while(p!二NULL)if(p->num=num)pO->next=p->next;free(p);flag=1;n;IelsePO=P;p=p->next;if(p->next=NULL)flag=O;if(flag=1)printf('n永久II除忖号学生的信息?(y/n)H,num);getchar();ch=getchar();if(ch='y'|ch=
15、Y)save_message();elseprintf('n 撤消 M 除!");getch();Ielseprintf('n JM 除失败!");getch();/*s询模妤/inquire_message()int i,flag=O;long num;struct STH *p;p=head=readfile();if(head=NULL)printfC文件读取出錯! “);getch();IelseprintfC 入要査询学生的学号 M;scanf('%ld",&num);for(i=0;i<n;i+)if(p->
16、num=num)printf('n 信息已找到:n");getch();clrscr();printfC*FOUND*nH);printf("nn");printf(PRINTF);printf(GESHI,p->num,p->name,p->sex,p->birth.year,p->birth.month,p->birth.day,p->xi,p->ban,p->add);printf('n眄;printfC* *END*n");flag=1;break;elsep=p->ne
17、xt;if(flag=O)printf("n无此人信息!");elsegetch();广显示模JT/output_message()int i=0;struct STH*p;p=head=readfile();if(head=NULL)printff文件读取岀錯! H);getch();elseclrscrf);printfCn*STUDENT*巧;printfCnH);printf(PRINTF);考试资料.while(i<n)printf(GESHI,p->num,p->name?p->sex,p->birth.year,p->bir
18、th.month,p->birth.day,p->xi,p->ban,p->add);p=p->next;i+;printfCnH);printf("*END*printf("n显示完毕! n ft%d条信息.n按任意建返SI主菜单M,n);getch();厂存档模ST/save_message()FILE *fp;int i;struct STH*p;p=head;if(fp=fopenCSTH.txt,w")=NULL)printfC读文件錯淚! !");exit(O);Ifprintf(fp,"%d'
19、,n);fprintf(fp,%c',7,);厂注恿要该"/for(i=0;i<n;i+)fpnntf(fp,"%ld %s %s %d %d %d %s %s %s : p->num,p->name,p->sex,p->birth.year,p->birt h.month,p->birth.day,p->xi,p->ban,p->add);p=p->next;Ifclose(fp);getch();void main(void)int choice;char ch;FILE *fp;struct d
20、ate d;getdate(&d);if(fp=fopenCSTH.txt",T,)=NULL)fp=fopenCSTH.txTt'w");fprintf(fp,"%d',O); fclose(fp);Ielsefscanf(fp,'%d:&n);printf(-n信息巳经保存在STH.txt文件中!);考试资料.fclose(fp);clrscr();printfCM 作人:«IO5O1 李艺凡“);printf("nnn");printfC*printfC欢jffliS人学生户籍系貌prin
21、tfCprintfCprintfCprintfCprintfCprintfCprintfCprintfCn");nn");1创建记录n");2添UU记录n");3查找记录n");4删除记录n");5修改记录5");6显示全部信息n");0退出程序);n");printfC%d $%d fi%d B",d.da_year,d.da_mon,d.da_day);考试资料.printfCn请选择(0-6 ):);scanf('%d",&choice);if(n=0)厂记录为空时不it其进行其他操作*/while(choice<0|choice>1)printfCifl录为空,无法操作ft ID;printf(Mi重新输人:(0 或 1 )n");scanf('%d",&choice);Ielsewhile(choice<0|choice>6)printfCi A有锲! n请重新输人:n");scanf('
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 江苏省南京市联合体2026届全国中考大联考信息卷:语文试题试卷(2)含解析
- 甘肃省白银市白银区重点中学2025-2026学年初三2月线上第一周周测英语试题含解析
- 2026届湖北省广水市城郊街道办事处中学心中学初三入学调研语文试题(2)试卷含解析
- 2025-2026学年新疆吉木乃初级中学初三4月中考模拟测试语文试题试卷含解析
- 2026年河南省三门峡市重点达标名校学业水平模拟考试英语试题仿真模拟试题B卷含解析
- 户外旅行安全防范指导书手册
- 企业会议组织策划及记录指南
- 高效团队协作与管理策略手册
- 个人文件档案管理责任书范文5篇
- 文化创意产业IP开发与运营策略研究计划
- 配电线路及设备巡视
- 蕉岭县幅地质图说明书
- 小班数学认识数字1-5
- 湘教版(2019)高中地理必修二知识点汇编(全一册)
- 小学科学教育科学三年级上册水和空气 宋伟空气占据空间吗说课稿
- 六大系统-矿井监测监控系统课件
- 北师大数学六年级下册第一单元《圆柱与圆锥》单元整体解读课件
- 考研考博-英语-中国美术学院考试押题卷含答案详解4
- 东北地区的地理位置与自然环境八年级地理湘教版公开课
- 江苏省幼儿园教育技术装备标准(一)
- 体育统计学课件1-8章1214
评论
0/150
提交评论