以下关于航班信息添加的程序貌似有问题,求大神修改。
#include<stdio.h>#include<stdlib.h>
#include<string.h>
struct Flight //航班信息结构//
{
char flightnumber[10],company[10],start[10],destination[10],starttime[10],arrivetime[10];
int price,ticket;
};
typedef struct Flight Flight;
Flight f1[100];
int h=5;
void display();
void input(); //航班信息输入函数//
void add();
void display()//display 函数//
{
int i=0;
printf("===============================================================\n");
printf("航班号 航空公司 起点 终点 起飞时间 到达时间 票价 座位数\n");
FILE *fp1;
if((fp1=fopen("e:\\flight.txt","r"))==NULL)
{
printf("创建文件失败!\n");
exit(1);
}
while(i<h)
{
fscanf(fp1,"%s%8s%9s%6s%8s%10s%7d%8d",f1[i].flightnumber,f1[i].company,f1[i].start,f1[i].destination,f1[i].starttime,f1[i].arrivetime,&f1[i].price,&f1[i].ticket);
fprintf(stdout,"%s%8s%9s%6s%8s%10s%7d%8d\n",f1[i].flightnumber,f1[i].company,f1[i].start,f1[i].destination,f1[i].starttime,f1[i].arrivetime,f1[i].price,f1[i].ticket);
i++;
}
fclose(fp1);
printf("===============================================================\n");
return;
}
void main()
{
char a[10];
FILE *fp5;
int i=0;
do
{
if((fp5=fopen("e:\\flight.txt","a+"))=NULL)
{
exit(1);
}
printf("===============================================================\n");
printf("请按照提示输入航班信息,按回车键结束输入\n\n");
FILE *fp1;
if((fp1=fopen("e:\\flight.txt","a"))==NULL)
{
printf("打开文件失败!\n");
exit(1);
}
Flight f2[100];
printf("请输入航班号:(例:F0001)\n");
scanf("%s",f2[i].flightnumber);
printf("请输入航空公司:\n");
scanf("%s",f2[i].company);
printf("请输入起点:\n");
scanf("%s",f2[i].start);
printf("请输入终点:\n");
scanf("%s",f2[i].destination);
printf("请输入起飞时间(例:07:30):\n");
scanf("%s",f2[i].starttime);
printf("请输入到达时间:\n");
scanf("%s",f2[i].arrivetime);
printf("请输入票价:\n");
scanf("%d",&f2[i].price);
printf("请输入座位数:\n");
scanf("%d",&f2[i].ticket);
printf("完成输入!\n");
fprintf(fp1,"%s%8s%9s%6s%8s%10s%7d%8d\n",f2[i].flightnumber,f2[i].company,f2[i].start,f2[i].destination,f2[i].starttime,f2[i].arrivetime,f2[i].price,f2[i].ticket);
fclose(fp1);
h++;
display();
printf("录入信息完成!\n\n");
fclose(fp5);
printf("是否继续添加?输入yes继续no退出!");
scanf("%s",a);
if(strcmp(a,"yes")==0)
break;
i++;
}while(1);
}