📄 出库表.cpp
字号:
#include "1.h"
//显示所有出库的记录
void out()
{FILE *form;
FILE *fg;
buy_list1 *a,*c,*heada;
buy_list1 *b,*d,*headb;
int i,k,zero=0;
int count1;
int count2;
a=NULL;
if((fg=fopen("pass2.txt","r+"))==NULL)//打开已经通过检查的文件*/
{printf("\n不能打开文件!\n");
exit(0);
}
fread(&count1,sizeof(int),1,fg);//读取pass2文件*/
if(count1){
for(i=0;i<count1;i++)
a=c=(buy_list1 *)malloc(sizeof(buy_list1));
heada=NULL;
for(i=0;i<count1;i++)
{if(i==0) heada=a;
else a->next=c;
a=c;
c=(buy_list1 *)malloc(sizeof(buy_list1));
fread(c,sizeof(buy_list1),1,fg);
}
a->next=c;
c->next=NULL;
a=heada->next;
fclose(fg);}
//printf("1");
if((form=fopen("out.txt","r+"))==NULL)//打开出库表
{printf("\n不能打开文件!\n");
exit(0);
}
//把出库表读到内存
fread(&count2,sizeof(int),1,form);
b=d=(buy_list1 *)malloc(sizeof(buy_list1));
headb=NULL;
for(i=0;i<count2;i++)
{if(i==0) headb=b;
else b->next=d;
b=d;
d=(buy_list1 *)malloc(sizeof(buy_list1));
fread(d,sizeof(buy_list1),1,form);
}
fclose(form);//关闭文件
b->next=d;
d->next=NULL;
while(a)
{
k=1;b=headb->next;
while(b)
{if(!strcmp(a->name,b->name)&&!strcmp(a->author,a->author)&&!strcmp(a->press,b->press))
{b->num=b->num+a->num;k=0;break;}
else b=b->next;
}//
if(k)
{b=headb;
while(b->next){b=b->next;}
count2++;
b->next=(buy_list)malloc(sizeof(buy_list1));
b=b->next;
b->next=NULL;
strcpy(b->name,a->name);
strcpy(b->author,a->author);
strcpy(b->press,a->press);
strcpy(b->buyer,"空");
strcpy(b->cla,"空");
b->num=a->num;
}
a=a->next;
}//没有的节点被新建,有的节点数目增加
//不知道什么原因记录比真正的多1
//printf("\n\n%d\n\n",count2);
//把已经通过检查的信息与出库记录连接*/
if((fg=fopen("pass2.txt","w+"))==NULL)
{printf("\n不能打开文件!\n");
exit(0);
}
fwrite(&zero,sizeof(int),1,form);
fclose(fg);
b=headb->next;
printf(" \t\t\t以下是出库记录\n");
printf("\t书名 作者\t 出版社\t 数量\n");
if((form=fopen("out.txt","w+"))==NULL)
{printf("\n不能打开文件!\n");
exit(0);
}
fwrite(&count2,sizeof(int),1,form);//写进出库
while(b)//输出整个出库
{
printf("\t%-15s %-15s%-15s %d\n",b->name,b->author,b->press,b->num);
fwrite(b,sizeof(buy_list1),1,form);
b=b->next;
}
fclose(form);
//printf("%d",count2);
system("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -