疑问求解答~ 谢谢!结构数组的初始化是否存在对程序造成了影响
请问,我先运行一次单个的,在这个程序之外的结构体文件,再运行一下下面的程序,就可以识别一样的航班,如果航班重复的话会让我重新输入。但是,如果我去掉struct flyline line【18】等号后边的一大串,为什么就不能识别相同航班了呢?也就是不论我输入什么航班都会顺利通过,正常来讲,有文件存在的情况下,不论我去不去掉那一大串,对程序来说是没有影响的啊
#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 line[18]={{"航班号","所属公司","出发地","降落地","起飞时间","预计飞行时间","机型","准点率","头等舱票价","头等舱剩余座位","经济舱票价","经济舱剩余座位","驾驶员","副驾驶\n"},
{"SC8835","山东航空公司","北京","珠海","6:35","210min","738","93%","¥5080","6","¥2030","33","Zhao Yi","Zhao Er\n"},
{"SC1195","山东航空公司","北京","银川","7:05","135min","738","98%","¥3540","8","¥1180","25","zhao san","zhao si\n"},
{"SC4785","山东航空公司","北京","盐城","8:00","115min","738","80%","¥1960","2","¥980","12","zhao wu","zhao liu\n"},
{"SC4852","山东航空公司","北京","青岛","9:50","90min","747","90%","¥1640","5","¥820","34" ,"zhao qi","zhao ba\n"},
{"SC4882","山东航空公司","北京","珠海","10:45","240min","635","96%","¥5240","2","¥2320","11","zhao jiu","zhao shi\n"},
{"SC4854","山东航空公司","北京","烟台","13:45","100min","482","92%","¥4200","0","¥2100","9","qian yi","qian er\n"},
{"SC4678","山东航空公司","北京","厦门","15:20","100min","482","95%","¥2440","5","¥1220","17","qian san","qian si\n"},
{"SC4856","山东航空公司","北京","重庆","20:05","185min","738","85%","¥3860","1","¥1980","3","qian wu","qian liu\n"},
{"3U8548","四川航空公司","成都","北京","6:25","190min","321","78%","¥4730","3","¥1690","28","qian qi","qian ba\n"},
{"3U8303","四川航空公司","哈尔滨","北京","6:50","120min","319","81%","¥3050","7","¥1520","13","qian jiu","qian shi\n"},
{"3U8896","四川航空公司","西昌","北京","7:25","305min","320","91%","¥4820","3","¥2410","3","sun yi","sun er\n"},
{"3U8838","四川航空公司","昆明","北京","8:10","295min","320","87%","¥3460","0","¥1730","23","sun san","sun si\n"},
{"3U8832","四川航空公司","万县","北京","17:30","140min","319","86%","¥2850","4","¥1920","5","sun wu","sun liu\n"},
{"3U8894","四川航空公司","成都","北京","19:30","190min","320","90%","¥4730","1","¥1690","0","sun qi","sun ba\n"},
{"3U8830","四川航空公司","重庆","北京","10:45","195min","321","87%","¥3660","4","¥1820","31","sun jiu","sun shi\n"},
{"3U8892","四川航空公司","三亚","北京","7:55","245min","321","93%","¥3870","2","¥1980","19","li san","li si\n"},
};
struct flyline finformation;
struct flyline s[81];
int main()
{
int i,p3,t3,q3;
do /*航班信息输入*/
{
p3=1;
q3=1;
t3=1;
printf("请输入一下您要更改的信息:\n");
printf("请输入新增航班号: ");
scanf("%s",&finformation.fnum);
printf("请输入所属公司: ");
scanf("%s",&finformation.fcompany);
printf("请输入出发地: ");
scanf("%s",&finformation.fstart);
printf("请输入降落地: ");
scanf("%s",&finformation.fend);
printf("请输入起飞时间: ");
scanf("%s",&finformation.fstime);
printf("请输入预计飞行时间: ");
scanf("%s",&finformation.ftime);
printf("请输入机型: ");
scanf("%s",&finformation.ftype);
printf("请输入准点率: ");
scanf("%s",&finformation.frate);
printf("请输入头等舱票价: ");
scanf("%s",&finformation.ftprice);
printf("请输入头等舱剩余座位: ");
scanf("%s",&finformation.ftrest);
printf("请输入经济舱票价: ");
scanf("%s",&finformation.fyprice);
printf("请输入经济舱剩余座位: ");
scanf("%s",&finformation.fyrest);
printf("请输入驾驶员: ");
getchar();/*接收回车符*/
gets(finformation.fp1);
printf("请输入副驾驶: ");
gets(finformation.fp2);
for(i=0;i<18;i++)
{
if(strcmp(line[i].fnum,finformation.fnum)==0) p3=0;
if(strcmp(line[i].fp1,finformation.fp1)==0) q3=0;
if(strcmp(line[i].fp2,finformation.fp2)==0) t3=0;
}
}while(p3==0||q3==0||t3==0);
FILE *fline;
int d1,n3_1=0;
fline=fopen("finformation.txt","ab+");/*打开文件*/
fseek(fline,0,SEEK_END);/*将新增航班信息加到结构末尾*/
fwrite(&finformation,sizeof(struct flyline),1,fline);/*将输入信息写入文件*/
fclose(fline);
printf("成功添加航班信息!\n");
fclose(fline);
//struct flyline s[81];
if((fline=fopen("finformation.txt","rb"))==NULL)
{
printf("文件读取失败……");
exit(0);
}
while(!feof(fline))/*统计全部航班信息个数*/
{
fread(&s[n3_1],sizeof(struct flyline),1,fline);
n3_1++;
}
for(d1=0;d1<n3_1;d1++)/*读取并输出全部航班信息*/
{
fread(&s[d1],sizeof(struct flyline),1,fline);
printf(" %-8s%-14s%-8s%-8s%-10s%-14s%-7s%-8s%-12s%-16s%-12s%-16s%-10s%-6s\n",s[d1].fnum,s[d1].fcompany,s[d1].fstart,s[d1].fend,s[d1].fstime,s[d1].ftime,s[d1].ftype,s[d1].frate,s[d1].ftprice,s[d1].ftrest,s[d1].fyprice,s[d1].fyrest,s[d1].fp1,s[d1].fp2);
}
fclose(fline);
return 0;
}