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

📄 购书表.cpp

📁 由于当时只是学到C语言
💻 CPP
字号:
#include <stdio.h>
#include <malloc.h> 
#include <stdlib.h> 
#include <string.h>
#include <conio.h>
#include <time.h>

typedef struct buy_list1{ //购书单
char name[20];  //书名
char author[10]; //作者
char press[20];//出版社
int num;       //数量
char buyer[10];  //购买人
char cla[20];    //班级
struct buy_list1 *next; 
}buy_list1,*buy_list;

void main()
{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("e:\\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("e:\\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;
printf("\n\n%d\n\n",count2);
//把已经通过检查的信息与代购表历史记录连接*/


if((fg=fopen("e:\\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("e:\\b.txt","w+"))==NULL)//打开购表文件*/
{printf("\n不能打开文件!\n");
 exit(0);
}
fwrite(&count2,sizeof(int),1,form);//写进代购表文件*/
while(b)//输出代购表文件信息*/
{
printf("%s    %s   %s   %s   %s    %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);

printf("%d",count2);



}

⌨️ 快捷键说明

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