#include
#include
#include
#include
typedef struct
{
int flightnum;
char name[15];
char IDcard[20];
int seatno;
} PASS;
typedef struct
{
int num;
char destin[15];
int limit;
int rest;
} FLIGHT;
void input_flight(FLIGHT *p)
{
scanf("%d%d%d%s",&p->num,&p->limit,&p->rest,p->destin);
}
void input_passanger(PASS *p)
{
scanf("%s%s%d ",p->name,p->IDcard, &p->seatno);
}
void save_flight(FLIGHT *p,FILE *fp)
{
fwrite(p,sizeof(FLIGHT),1,fp);
}
void save_passanger(PASS *p,FILE *fp,int j)
{
fwrite(p,sizeof(PASS),j,fp);
}
void main()
{
FILE *fp1,*fp2;
FLIGHT *Dlink;
PASS *clist;
int i;
int j;
int k;
int max;
if((fp1=fopen("file1.dat","wb"))==NULL)
{
printf("the file can't be opend\n");
exit(0);
}
if((fp2=fopen("file2.dat","wb"))==NULL)
{
printf("the file can't be opend");
exit(0);
}
printf("please input the sum of the flight\n");
scanf("%d",&max);
for(i=1;i<=max;i++)
{
printf("please input the information of flight\n");
Dlink=(FLIGHT*)malloc(sizeof(FLIGHT));
printf("flight's number,limit,rest,destin\n");
input_flight(Dlink);
save_flight(Dlink,fp1);
printf("please input the information of passanger\n");
j=((Dlink->limit)-(Dlink->rest));
clist=(PASS*)malloc(j*sizeof(PASS));
(clist->flightnum)=(Dlink->num);
printf("passanger's name,IDcard,seatno\n");
for(k=1;k<=j;k++)
{
input_passanger(clist);
clist++;
}
clist=(clist-(j-1));
save_passanger(clist,fp2,j);
free(Dlink);
for(k=1;k<=j;k++)
{
clist=(clist-(j-1));
free(clist);
clist++;
}
}
fclose(fp1);
fclose(fp2);
}