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

📄 购书清单.cpp

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

void stu_buy()
{FILE *form;
 FILE *fg;
 buy_list1 *a,*c,*heada;
 buy_list1 *b,*d,*headb;
 int i,m,zero=0;
 int count1;
 int count2;


a=NULL;
if((fg=fopen("pass1.txt","r+"))==NULL)//打开已经通过检查的文件*/
{printf("\n不能打开文件!\n");
exit(0);
}
fread(&count1,sizeof(int),1,fg);//读取pass1文件*/
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("b.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.txt
b->next=d;
d->next=a;

//把已经通过检查的信息与代购表历史记录连接*/


if((fg=fopen("pass1.txt","w+"))==NULL)
{printf("\n不能打开文件!\n");
 exit(0);
}

fwrite(&zero,sizeof(int),1,form);
fclose(fg);

b=headb->next;
count2+=count1;
if((form=fopen("b.txt","w+"))==NULL)//打开购表文件*/
{printf("\n不能打开文件!\n");
 exit(0);
}
	printf("\t\t\t以下是有史以来的购书清单\n");
	printf("班级\t       姓名\t      书名           作者\t   出版社\t   数量\n");		
fwrite(&count2,sizeof(int),1,form);//写进表文件*/
while(b)//输出信息*/
{
		printf("%-15s%-15s%-15s%-15s%-15s%d\n",b->cla,b->buyer,b->name,b->author,b->press,b->num);
fwrite(b,sizeof(buy_list1),1,form);
b=b->next;
}

fclose(form);



    system("pause");

}

⌨️ 快捷键说明

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