int outstocknum; struct date outtime; char delivername[20]; }out[OUTSTOCKNUM];
//------------------------------------------------------------------------- void CreatStock()//创建库存记录文件 { int i; FILE *fp;
if((fp=fopen(\{
printf(\open file!\\n\exit(0); }
for(i=0;i printf(\请输入电器的信息!\\n\ printf(\电器名称 品牌名称 型号 库存数量 价值\\n\ scanf(\%s %s %d %d\num,&stoc[i].value); fwrite(&stoc[i],sizeof(struct stock),1,fp); } fclose(fp); } //----------------------------------------------------------------------------- int read_stock()//读取库存文件到stoc[] { int i=0; FILE *fp; if((fp=fopen(\{ printf(\open file :stock.txt !\\n\return 0; } if( fgetc(fp)<0 ) //读入的是文件结束符 return 0; rewind(fp);//使位置指针重新移到文件开头 while( !feof(fp) ) { fread(&stoc[i],sizeof(struct stock),1,fp); i++; } fclose(fp); return --i;//返回库存家电的种类 } //---------------------------------------------------- int read_instock()//读取入库文件到in[] { int i=0; FILE *fp; if((fp=fopen(\{ printf(\open file :instock.txt !\\n\return 0; } if( fgetc(fp)<0 ) return 0; rewind(fp); while( !feof(fp) ) { fread(&in[i],sizeof(struct instock),1,fp); i++; } fclose(fp); return --i;//返回入库家电的种类 } //----------------------------------------------------- int read_outstock()//读取出库文件到out[] { int i=0; FILE *fp; if((fp=fopen(\{ printf(\open file :outstock.txt !\\n\return 0; } if( fgetc(fp)<0 ) return 0; rewind(fp); while( !feof(fp) ) { fread(&out[i],sizeof(struct outstock),1,fp); i++; } fclose(fp); return --i;//返回出库家电的种类 } //----------------------------------------------------------------------------- void CreatInstock()//创建入库记录并改变库存记录 { int i,j,k; int an=STOCKNUM; int boolean=0; FILE *fp; if((fp=fopen(\{ printf(\open file!\\n\exit(0); } for(i=0;i printf(\电器名称 品牌名称 型号 入库数量 单价 入库时间(年 月 日) 送货人姓名\\n\ scanf(\%s %s %d %d %d %d %d %s\n[i].instocknum,&in[i].price,&in[i].intime.year,&in[i].intime.month,&in[i].intime.day,in[i].sendername); printf(\有物资入库!\\n\ fwrite(&in[i],sizeof(struct instock),1,fp); } fclose(fp); read_instock();//读取instock.txt入in[]; read_stock();//读取stock.txt入stoc[]; for(k=0;k boolean=0; for(j=0;j if(strcmp(stoc[j].elename,in[k].elename)==0 && strcmp(stoc[j].brand,in[k].brand )==0 && strcmp(stoc[j].type ,in[k].type )==0 ) { stoc[j].stocknum =stoc[j].stocknum +in[k].instocknum ; boolean=1; } } if( boolean==0 )//原来库存中没有此类家电 { strcpy(stoc[an].elename ,in[k].elename ); strcpy(stoc[an].brand ,in[k].brand ); strcpy(stoc[an].type ,in[k].type ); stoc[an].stocknum =in[k].instocknum ; stoc[an].value=in[k].price ; an++; }