⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 进书改库存.cpp

📁 由于当时只是学到C语言
💻 CPP
字号:
#include "1.h"

void in_sto()
{buy_list1 *p,*headq,*q,*headp,*c,*d;//q是in文件,p是库存
int k,count_in,count_st,i;
FILE *fg;

p=NULL;
q=NULL;

if((fg=fopen("in.txt","r"))==NULL)//打开要进库的文件
{printf("\n不能打开文件!\n");
exit(0);
}

fread(&count_in,sizeof(int),1,fg);

if(count_in){//如果数量不为0的话执行一下操作,否则关闭文件不做操作

q=c=(buy_list1 *)malloc(sizeof(buy_list1));
headq=NULL;
for(i=0;i<count_in;i++)
{if(i==0) headq=q;
 else q->next=c;
   q=c;
   c=(buy_list1 *)malloc(sizeof(buy_list1));
   fread(c,sizeof(buy_list1),1,fg);
}

fclose(fg);
q->next=c;
c->next=NULL;

/*q=headq->next;
while(q)
{
printf("%s    %s   %s   %s   %s    %d\n",q->cla,q->buyer,q->name,q->author,q->press,q->num);
q=q->next;
}*/

q=headq->next;


if((fg=fopen("store.txt","r"))==NULL)//打开库存文件
{printf("\n不能打开文件!\n");
exit(0);
}

fread(&count_st,sizeof(int),1,fg);
p=d=(buy_list1 *)malloc(sizeof(buy_list1));
headq=NULL;
for(i=0;i<count_st;i++)
{if(i==0) headp=p;
 else p->next=d;
   p=d;
   d=(buy_list1 *)malloc(sizeof(buy_list1));
   fread(d,sizeof(buy_list1),1,fg);
}


fclose(fg);

p->next=d;
d->next=NULL;

/*p=headp->next;
while(p)
{
printf("%s    %s   %s   %s   %s    %d\n",p->cla,p->buyer,p->name,p->author,p->press,p->num);
p=p->next;
}
printf("\n\n\n\n\n");*/
p=headp->next;
/*while(p->next)
{p=p->next;
}
p->next=q;*/
p=headp->next;
while(q)
{k=1;p=headp->next;
 while(p)
{if(!strcmp(q->name,p->name)&&!strcmp(q->author,p->author)&&!strcmp(q->press,p->press))
 {p->num=p->num+q->num;k=0;break;}
 else p=p->next;
 }//while(p)

 if(k)
 {p=headp;
 while(p->next){p=p->next;}
count_st+=count_in;	 
 p->next=(buy_list)malloc(sizeof(buy_list1));
 p=p->next;
  p->next=NULL;
  strcpy(p->name,q->name);
  strcpy(p->author,q->author);
  strcpy(p->press,q->press);
   strcpy(p->buyer,"空");
    strcpy(p->cla,"空");
  p->num=q->num;
 }
q=q->next;
}


/*p=headp->next;
while(p)
{
printf("%s    %s   %s   %s   %s    %d\n",p->cla,p->buyer,p->name,p->author,p->press,p->num);
p=p->next;
}*/


if((fg=fopen("store.txt","w"))==NULL)//打开库存文件
{printf("\n不能打开文件!\n");
exit(0);
}
p=headp->next;
fwrite(&count_st,sizeof(int),1,fg);
while(p)//输出代购表文件信息*/
{

fwrite(p,sizeof(buy_list1),1,fg);
p=p->next;
}
fclose(fg);

i=0;
if((fg=fopen("in.txt","w"))==NULL)//打开库存文件
{printf("\n不能打开文件!\n");
exit(0);
}
fwrite(&i,sizeof(int),1,fg);
}else fclose(fg);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -