资源描述:
《超市管理系统源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#includestructgoodinfo{charno[15];charname[15];floatprice;}good[1000];intflag;/*全局变量,在search函数中用于标记查询到的商品的序号,传递到edit()函数中*/intflag2=0;/*全局变量,在delete()中当flag2=1时终止search()中查询商品的循环*/voidadd(){structgoodinfogood1;chara[3]="00";
2、intflag2=0;intm,j=0;FILE*fp;fp=fopen("goodinfo.c","ab+");if(fp==NULL){printf("erroronopenthefile!!!");getchar();exit(0);}while(1){printf("pleaseinputgoodsinformationtoaddit!!input"00"togiveupadding!!");printf("no:");scanf("%s",good1.no);if(str
3、cmp(good1.no,a)==0)break;for(j=0;j<1000;j++){fread(&good[j],sizeof(structgoodinfo),1,fp);if(strcmp(good[j].no,good1.no)==0){flag2=1;printf("thegoodsalreadyexists!!!");break;}}if(flag2==1)break;printf("name:");scanf("%s",good1.name);printf("price:");
4、scanf("%f",&good1.price);m=fwrite(&good1,sizeof(structgoodinfo),1,fp);if(m!=1)printf("erroradding!!!");else{printf("successinaddingthefollowinginformation!!");printf("no:%s,name:%s,price:%.2fRMB",good1.no,good1.name,good1.price);}rewind(fp);}fcl
5、ose(fp);}voidsearch(){inti=0,j;charno1[15],no2[3]="00";FILE*fp;fp=fopen("goodinfo.c","ab+");if(fp==NULL){printf("erroronopenthefile!!!");getchar();exit(0);}while(1){printf("pleaseinputtheno.youwanttosearch!!!input"00"toquit!!");scanf("%s",no1);if(
6、strcmp(no1,no2)==0)break;for(i=0;i<1000;i++)fread(&good[i],sizeof(structgoodinfo),1,fp);for(j=0;j<1000;j++){if(strcmp(good[j].no,no1)==0)break;}if(j==1000)printf("cannotfindthegoods!!!");else{printf("findit!!thegoods'informationis:%d",flag);printf
7、("no:%s,name:%s,price:%.2f",good[j].no,good[j].name,good[j].price);flag=j;/*将查询到的商品在数组good中的序号传递出去*/if(flag2==1)break;/*在delete函数中用于终止while(1)的循环*/}}fclose(fp);}intdelete(){inti;charch;FILE*fp;flag2=1;/*flag2置1,在调用search函数时终止其循环*/search();getcha
8、r();/*接受回车符号,防止干扰选项*/printf("Areyousuretodeleteit?");printf("'Y'or'y'->YES.'N'or'n'->NO");ch=getchar();switch(ch){case'n':case'N':{printf("deletecanceled!!!");return0;}case'y':case'Y':printf("deleting,pleasewait!!!!");break;defau