?? 出庫表.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 + -