西安邮电大学 C语言实习 医院管理系统 下载本文

if (p->id1==id1) { printf(\编号\\t姓名\\t性别\\t年龄\\t病情\\t电话\\n\ printf(\p->tele1); printf(\请选择修改:\\n1.编号 2.姓名 3.性别 4.年龄 5.病情 6.电话\\n\ scanf(\ switch(choice) { case 1: printf(\编号:\ scanf(\ printf(\%s %s %s\\n\ele1); save1(h); return 1; case 2: printf(\姓名:\ scanf(\ printf(\%s %s %s\\n\ele1); save1(h); return 1; case 3: printf(\性别(请输入男(male)女(female)):\ scanf(\ printf(\%s %s %s\\n\ele1); save1(h); return 1; case 4: printf(\年龄:\ scanf(\ printf(\%s %s %s\\n\ele1); save1(h); return 1; case 5: printf(\病情:\ scanf(\ printf(\%s %s %s\\n\ele1);

save1(h); return 1; case 6: printf(\电话:\ scanf(\ printf(\%s %s %s\\n\ele1); save1(h); return 1; } } p=p->next; } save1_bianji(h); return 0; }

//药品信息相关函数的定义 void medicine() { system(\ Display2(); }

void inp2() { struct medicine *m,*q; m=creat2(); save2(m); q=read2(); print2(q); }

void Insert2() { struct medicine *head; head=read2(); if(insert2(head)) printf(\已成功插入!\\n\插入 else printf(\有重号插入失败!\\n\ printf(\按任意键返回主菜单\ getch(); Display(); }

/*录入数据*/

struct medicine *creat2()//尾插法建立头结点的单链表

{ struct medicine*head,*r,*m; int i=0; char choice; system(\ head=(struct medicine *)malloc(sizeof(struct medicine)); head->next=NULL; r=head; do { m=(struct medicine *)malloc(sizeof(struct medicine)); printf(\请输入药品信息\\n\ printf(\第%d个药品的信息:\\n\ printf(\编号:\ flushall(); scanf(\ printf(\药名:\ flushall(); scanf(\ printf(\用于治疗:\ flushall(); scanf(\ printf(\单价:\ flushall(); scanf(\ r->next=m; r=m; printf(\?(Y、N)\ choice=getche(); }while(choice=='Y'||choice=='y'); r->next=NULL; return(head); }

/*存储数据*/

void save2(struct medicine *h)//将单链表中的信息保存到指定的磁盘文件中 { struct medicine *m; FILE *fp; if((fp=fopen(\ { printf(\写文件出错,按任意键退出!\ getch(); exit(1); } for(m=h->next;m!=NULL;m=m->next) fprintf(fp,\ printf(\文件已成功保存,按任意键继续!\ getch();

fclose(fp); }

void save2_bianji(struct medicine *h)//将单链表中的信息保存到指定的磁盘文件中 { struct medicine *m; FILE *fp; if((fp=fopen(\ { printf(\写文件出错,按任意键退出!\ getch(); exit(1); } for(m=h->next;m!=NULL;m=m->next) fprintf(fp,\ printf(\文件已成功保存,按任意键继续!\ getch(); fclose(fp); }

//读取数据

struct medicine *read2()//从指定磁盘中读取信息并存入单链表中 { struct medicine *head,*r,*m; FILE *fp; if((fp=fopen(\ { printf(\读文件出错,按任意键退出!\ getch(); exit(1); } head=(struct medicine *)malloc(sizeof(struct medicine)); head->next=NULL; r=head; while(!feof(fp))//文件未结束 {//开辟空间,以存放读取的信息 m=(struct medicine *)malloc(sizeof(struct medicine)); //存放读取信息

fscanf(fp,\ r->next=m; r=m; } r->next=NULL; fclose(fp); printf(\文件中信息已正确读出,按任意键继续!\ getch(); return(head); }

//输出数据