试试这个。
反正我试了是没问题的,就是格式有点问题,一行容不了那么多
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define whole 81
struct flyline
{
char fnum[whole];
char fcompany[whole];
char fstart[whole];
char fend[whole];
char fstime[whole];
char ftime[whole];
char ftype[whole];
char frate[whole];
char ftprice[whole];
char ftrest[whole];
char fyprice[whole];
char fyrest[whole];
char fp1[whole];
char fp2[whole];
};
struct flyline fl[81];
int main(int argc, char *argv[])
{
char num4[10];
int n=0,i,z4;
FILE *fi;
int h4,c4;
struct flyline line[31]={{"航班号","所属公司","出发地","降落地","起飞时间","预计飞行时间","机型","准点率","头等舱票价","头等舱剩余座位","经济舱票价","经济舱剩余座位","驾驶员","副驾驶\n"},
{"SC8835","山东航空公司","北京","珠海","7","210min","738","93%","5080","6","2030","33","Zhao Yi","Zhao Er\n"},
{"SC1195","山东航空公司","北京","银川","7","135min","738","98%","3540","8","1180","25","zhao san","zhao si\n"},
{"SC4785","山东航空公司","北京","盐城","8","115min","738","80%","1960","2","980","12","zhao wu","zhao liu\n"},
{"SC4852","山东航空公司","北京","青岛","10","90min","747","90%","1640","5","820","34" ,"zhao qi","zhao ba\n"},
{"SC4882","山东航空公司","北京","珠海","11","240min","635","96%","5240","2","2320","11","zhao jiu","zhao shi\n"},
{"SC4854","山东航空公司","北京","烟台","14","100min","482","92%","4200","0","2100","9","qian yi","qian er\n"},
{"SC4678","山东航空公司","北京","厦门","15","100min","482","95%","2440","5","1220","17","qian san","qian si\n"},
{"SC4856","山东航空公司","北京","重庆","20","185min","738","85%","3860","1","1980","3","qian wu","qian liu\n"},
{"3U8548","四川航空公司","成都","北京","6","190min","321","78%","4730","3","1690","28","qian qi","qian ba\n"},
{"3U8303","四川航空公司","哈尔滨","北京","7","120min","319","81%","3050","7","1520","13","qian jiu","qian shi\n"},
{"3U8896","四川航空公司","西昌","北京","7","305min","320","91%","4820","3","2410","3","sun yi","sun er\n"},
{"3U8838","四川航空公司","昆明","北京","8","295min","320","87%","3460","0","1730","23","sun san","sun si\n"},
{"3U8832","四川航空公司","万县","北京","17","140min","319","86%","2850","4","1920","5","sun wu","sun liu\n"},
{"3U8894","四川航空公司","成都","北京","19","190min","320","90%","4730","1","1690","0","sun qi","sun ba\n"},
{"3U8830","四川航空公司","重庆","北京","10","195min","321","87%","3660","4","1820","31","sun jiu","sun shi\n"},
{"3U8892","四川航空公司","三亚","北京","7","245min","321","93%","3870","2","1980","19","li san","li si\n"},
};
int d1,p4;
FILE*fline;
if((fline=fopen("finformation.txt","w"))==NULL)
{
printf("文件读取失败……");
}
for(i=0;i<17;i++)
fwrite(&line[i],sizeof(struct flyline),1,fline);
n=i;
fclose(fline);
fi=fopen("finformation.txt","r");
if(fi==NULL)
{
printf("文件打开失败,请重新打开... ...\n");
exit(1);
}
i=0;
while(!feof(fi))
{
fread(&fl[i],sizeof(struct flyline),1,fi);
i++;
}
do{
printf("请输入航班号(如AB1234):\n");
scanf("%s",num4);
for(i=0;i<n;i++)
{
if((strcmp(fl[i].fnum,num4))==0)
{
z4=i;
p4=0;
printf("您所查询的航班为:\n");
printf("
%-8s%-8s%-8s%-10s%-14s%-8s%-16s%-12s%-16s\n","航班号","出发地","降落地","起飞时间","预计飞行时间","头等舱票价","头等舱剩余座位","经济舱票价","经济舱剩余座位");
printf("
%-8s%-8s%-8s%-10s%-14s%-8s%-16s%-12s%-16s\n",fl[i].fnum,fl[i].fstart,fl[i].fend,fl[i].fstime,fl[i].ftime,fl[i].ftprice,fl[i].ftrest,fl[i].fyprice,fl[i].fyrest);
break;
}
else
p4=1;
}
if(p4==1)
printf("重新输入:\n");
}while(num4[0]!='q');
fclose(fi);
return 0;
}