#includestdio.h#includestring.h#includestdlib.h#includetime.h#includeconio.htypedefstructDrug{charDrug_id[30];//编号charDrug_name[50];//药品名称charDrug_type[10];//类型floatDrug_price;//价格intamount;//库存数量charDrug_time[30];//入库时间charremark[30];//备注structDrug*next;}Drug,*DrugPtr;#defineMENU欢迎进入药品管理系统\n\1:查看已有药品列表\n\2:添加新的药品\n\3:删除药品信息\n\4:修改药品信息\n\5:分类查询\n\0:退出\n\请您选择:#defineMENU41请选择要修改的选项\n\1:修改药品名称\n\2:修改药品价格\n\3:修改药品数量\n\4:修改药品类型\n\5:修改药品备注\n\0:返回主菜单\n\请您选择:#defineMENU5欢迎进入分类查询页面\n\1:按编号查询\n\2:按名称查询\n\3:按类型查询\n\4:按价格查询\n\5:按库存数量查询\n\6:按入库时间查询\n\0:返回主菜单\n\请您选择:#defineMENU50按药品编号查询\n\请输入要查询的药品编号:#defineMENU51按药品名称查询\n\请输入要查询的药品名称:#defineMENU52按药品类型查询\n\请输入要查询的药品类型:\n\1:中药\n\2:中成药\n\3:西药\n\0:返回查询菜单\n\请您选择:#defineMENU53按药品价格查询\n\请输入要查询的药品价格:#defineMENU54按药品库存数量查询\n\请输入要查询的药品的库存数量:#defineMENU55按药品入库时间查询\n\请输入要查询的药品入库时间:#defineSTRCMP(NAME,STR)strcmp((char*)GetStdin(请输入药品的编号(按0结束):,%s,STR),0)DrugPtrinsert(DrugPtrhead,intid,char*name);//添加药品voidsave_to_file(DrugPtr&yaolist);//将更新后的链表保存到文件中voidread_to_list(DrugPtr&yaolist);//将文件读入链表void*GetStdin(constchar*numstr,char*control,void*ret);DrugPtrgetvalue();//取值voiddruginsert(DrugPtr&yaolist,DrugPtryao);//插入操作intisdrugin(DrugPtryaolist,DrugPtryao);//判断voiddrugmodify(DrugPtr&yaolist,DrugPtryao);//修改操作voiddeletenode(DrugPtr&yaolist,chardrug_id[]);//删除操作voiddeletedrug(DrugPtr&yaolist);voidupdatedrug(DrugPtr&yaolist);voidlistshow(DrugPtryaolist);//显示操作voiddrug_find_name(DrugPtrhead,char*name);//以名称查询voiddrug_find_id(DrugPtrhead,char*id);//以编号查询voiddrug_find_type_z(DrugPtrhead);//查询中药voiddrug_find_type_zc(DrugPtrhead);//查询中成药voiddrug_find_type_x(DrugPtrhead);//查询西药voiddrug_find_price(DrugPtrhead,floatprice);//以价格查询voiddrug_find_amout(DrugPtrhead,intamout);//以库存数量查询voiddrug_find_time(DrugPtrhead,char*time);//以入库时间查询voiddrug_type_choose(DrugPtrhead);//查询主菜单voidchoose_type(DrugPtrhead);//类型查询intmain(){intchoice;DrugPtrhead=NULL;DrugPtryao;read_to_list(head);while(*(int*)GetStdin(MENU,%d,&choice)){switch(choice){case1:listshow(head);//显示药品列表break;case2:{yao=getvalue();druginsert(head,yao);//添加药品printf(药品添加成功\n);break;}case3:deletedrug(head);//删除药品break;case4:updatedrug(head);//修改药品信息break;case5://分类查询drug_type_choose(head);break;case0://退出break;}}save_to_file(head);return0;}void*GetStdin(constchar*numstr,char*control,void*ret){cputs(numstr);while(!scanf(control,ret)){fflush(stdin);system(cls);cputs(numstr);}system(cls);returnret;}//显示列表voidlistshow(DrugPtryaolist){printf(%5s%13s%10s%10s%13s%10s%10s\n,药品编号,名称,价格,类型,入库时间,库存数量,备注);DrugPtrp=yaolist;if(!p)printf(kong);while(p){printf(%-5s%-18s%-10.2f%-10s%-13s%-6d%-10s\n,p-Drug_id,p-Drug_name,p-Drug_price,p-Drug_type,p-Drug_time,p-amount,p-remark);p=p-next;}}DrugPtrgetvalue(){DrugPtryao=(DrugPtr)malloc(sizeof(Drug));printf(请输入药品编号:);scanf(%s,&yao-Drug_id);printf(\n);printf(请输入药品名称:);scanf(%s,&yao-Drug_name);printf(\n);printf(请输入药品价格:);scanf(%f,&yao-Drug_price);printf(\n);printf(请输入药品数量:);scanf(%d,&yao-amount);printf(\n);printf(请输入药品入库时间:);scanf(%s,&yao-Drug_time);printf(\n);printf(请输入药品类型:);scanf(%s,&yao-Drug_type);printf(\n);printf(请输入药品备注:);scanf(%s,&yao-remark);printf(\n);yao-next=NULL;returnyao;}voiddruginsert(DrugPtr&yaolist,DrugPtryao){if(!yaolist)yaolist=yao;else{yao-next=yaolist-next;yaolist-next=yao;}}DrugPtrisdrugin(DrugPtryaolist,chardrug_id[]){DrugPtrp=yaolist;while(p){if(!strcmp(p-Drug_id,drug_id))break;elsep=p-next;}returnp;}//更新结点voiddrugmodify(DrugPtr&yaolist,DrugPtryao){intchoice;DrugPtrp=yaolist;floatt=0;//没有这句出现floatpointnotloadedwhile(*(int*)GetStdin(MENU41,%d,&choice)){switch(choice){case1:GetStdin(请输入药品的新名称:,%s,yao-Drug_name);printf(\n);cputs(更新成功!请继续选择\n);printf(\n);break;case2:GetStdin(请输入药品的新价格:,%f,&yao-Drug_price);printf(\n);cputs(更新成功!请继续选择\n);printf(\n);break;case3:GetStdin(请输入药品的修改数量:,%d,&yao-amount);printf(\n);cputs(更新成功!请继续选择\n);printf(\n);break;case4:GetStdin(请输入药品的新类型:,%s,yao-Drug_type);printf(\n);cputs(更新成功!请继续选择\n);printf(\n);break;case5:GetStdin(请输入药品的新备注:,%s,yao-remark);printf(\n);cputs(更新成功!请继续选择\n);printf(\n);break;case0:break;}}}//找到结点返回updatevoidupdatedrug(DrugPtr&yaolist){charstring[30];DrugPtryao;while(strcmp((char*)GetStdin(请输入药品编号(按0结束):\n,%s,string),0)){yao=isdrugin(yaolist,string);if(yao)//判断药是否存在drugmodify(yaolist,yao);elseprintf(没有这种药\n);}}voiddeletedrug(DrugPtr&yaolist){charstring[30];while(STRCMP(SECOND,string)){if(isdrugin(yaolist,string)){deletenode(yaolist,string);}elseprintf(药品不存在!);}}voiddeletenode(DrugPtr&yaolist,chardrug_id[]){DrugPtrq,p;q=yaolist;p=q-next;if(!strcmp(yaolist-Drug_id,drug_id)){yaolist=yaolist-next;free(q);}else{while(p){if(!strcmp(p-Drug_id,drug_id))break;q=q-next;p=p-next;}q-next=p-next;free(p);}printf(药品已删除!);}voidread_to_list(DrugPtr&yaolist){FILE*fp=fopen(E:/yao.txt,r);if(!fp)printf(error);while(!feof(fp)){DrugPtryao=(DrugPtr)malloc(sizeof(Drug));yao-next=NULL;fscanf(fp,%s%s%f%s%s%d%s\n,yao-Drug_id,yao-Drug_name,&yao-Drug_price,yao-Drug_type,yao-Drug_time,&yao-amount,yao-remark);druginsert(yaolist,yao);}fclose(fp