#include <> #include <> #include <>
#define NOD struct plane_list struct plane
{char number [10]; char start[10]; char arrive [10]; char date[10]; char starttime[10]; char arrivingtime[10]; char price[10]; char model[10]; }; NOD
{char number [10]; char start[10]; char arrive [10]; char date[10]; char starttime[10]; char arrivingtime[10]; char price[10]; char model[10]; NOD*next; };
FILE *fp;
/*由文件中的数据生成一个飞机航班的链表,如果文件不存在,则是一个空链表*/ NOD *load(char planename[]) { NOD *p,*q,*head; struct plane per;
p=(NOD *)malloc(sizeof(NOD)); q=head=NULL;
if((fp=fopen(planename,\ return head; else
{ while(!feof(fp))
{ if(fread(&per,sizeof(struct plane),1,fp)==1) { p=(NOD *)malloc(sizeof(NOD)); strcpy(p->number,; strcpy(p->start,; strcpy(p->arrive,; strcpy(p->date,; strcpy(p->starttime,;
strcpy(p->arrivingtime,; strcpy(p->price,; strcpy(p->model,; head=p; p->next=q; q=head; } } }
fclose(fp); return(head); }
/*输入*/
NOD *insert(NOD *head) { NOD *temp,*p; p=head;
temp=(NOD *)malloc(sizeof(NOD)); printf(\请输入航班号:\ scanf(\ printf(\请输入起点站:\ scanf(\ printf(\请输入终点站:\ scanf(\ printf(\请输入起飞时间:\ scanf(\ printf(\请输入到达时间:\ scanf(\ printf(\请输入班期:\ scanf(\ printf(\请输入票价:\ scanf(\
printf(\请输入航班型号:\ scanf(\ head=temp; temp->next=p; return head; }
/*保存*/
void save(NOD *head, char filename[]) {NOD*p;
struct plane per;
if((fp=fopen(filename,\
{printf(\文件无法写入\
exit(0); } else
{ p=head; while(p!=NULL)
{ strcpy,p->number); strcpy,p->start); strcpy,p->arrive); strcpy,p->date); strcpy,p->starttime); strcpy,p->arrivingtime); strcpy,p->price); strcpy,p->model); if(fwrite(&per,sizeof(struct plane),1,fp)!=1)
{printf(\文件不能写入数据,请检查后重新运行.\\n\ exit(0); } p=p->next; }
fclose(fp); } }
/*显示*/
void display(NOD *head) { NOD *p; p=head;
while(p!=NULL)
{ printf(\航班号:%s\\n\ printf(\起点站:%s\\n\ printf(\终点站:%s\\n\ printf(\班期:%s\\n\
printf(\起飞时间:%s\\n\ printf(\到达时间:%s\\n\ printf(\票价:%s\\n\
printf(\飞机型号:%s\\n\ p=p->next;} }
/*航班号查找*/
void finda(NOD *head) { NOD *p;
char number[10];
printf(\请输入查找航班的编号:\ scanf(\ p=head;
while (p!=NULL)
{ if(strcmp(number,p->number)==0) { printf(\航班号:%s\\n\ printf(\起点站:%s\\n\ printf(\终点站:%s\\n\ printf(\班期:%s\\n\
printf(\起飞时间:%s\\n\ printf(\到达时间:%s\\n\ printf(\票价:%s\\n\
printf(\飞机型号:%s\\n\ break; } else p=p->next; }
if(p==NULL) }
printf(\查无此航班\\n\
/*起点站查找*/
void findb(NOD *head) { NOD *p;
char start[10];
printf(\请输入查找航班的起点站:\ scanf(\ p=head;
while (p!=NULL)
{ if(strcmp(start,p->start)==0) { printf(\航班号:%s\\n\ printf(\起点站:%s\\n\ printf(\终点站:%s\\n\ printf(\班期:%s\\n\
printf(\起飞时间:%s\\n\ printf(\到达时间:%s\\n\ printf(\票价:%s\\n\
printf(\飞机型号:%s\\n\ break; }
else p=p->next; }
if(p==NULL)
printf(\查无此航班\\n\ }
/*终点站查找*/
void findc(NOD *head) { NOD *p;
char arrive[10];
printf(\请输入查找航班的终点站:\ scanf(\ p=head;
while (p!=NULL)
{ if(strcmp(arrive,p->arrive)==0) { printf(\航班号:%s\\n\ printf(\起点站:%s\\n\ printf(\终点站:%s\\n\ printf(\班期:%s\\n\
printf(\起飞时间:%s\\n\ printf(\到达时间:%s\\n\ printf(\票价:%s\\n\
printf(\飞机型号:%s\\n\ break; } else p=p->next; }
if(p==NULL) printf(\查无此航班\\n\ }
/*起飞时间查找*/ void findd(NOD *head) { NOD *p;
char starttime[10];
printf(\请输入查找航班的起飞时间:\ scanf(\ p=head;
while (p!=NULL)
{ if(strcmp(starttime,p->starttime)==0) { printf(\航班号:%s\\n\ printf(\起点站:%s\\n\ printf(\终点站:%s\\n\ printf(\班期:%s\\n\
航班查询系统 C语言源程序
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)