#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
typedef struct airline
{
char line_num[10];//航班号
char start_place[20];//起飞地
char end_place[20];//目的地
char start_time[10];//起飞时间
char end_time[10];//降落时间
int total;//座位总数
int left;//剩余座位
int count;
struct airline *next;//下一个结点
} airline,*Airline;
//*初始化单链表**//
void InitList_1(Airline*pheadline)
{
*pheadline=(Airline)malloc(sizeof(airline));
(*pheadline)->next=NULL;
}
airline* Put_Flight_Information(int n, Airline pheadline)//录入航班函数: n为所要录入航班的数量:
{
//color(4);
int i;
int b;
airline *temp,*p,*Investigation;
p=pheadline;
pheadline->count = n;
for(i=0; i<n; i++)
{
temp=(airline*)malloc(sizeof(airline));
printf("\t\t请输入第%d个航班的航班号:\n\t\t",i+1);
scanf("%s",temp->line_num);
Investigation=pheadline->next;
while(Investigation!=NULL)
{
if(strcmp(Investigation->line_num,temp->line_num)!=0)
{
Investigation=Investigation->next;
}
else
{
printf("\t\t您输入的航班号重复,请重新输入:\n\t\t");
scanf("%s",temp->line_num);
Investigation=pheadline->next;
}
}
printf("\t\t请输入第%d个航班起飞点\n\t\t",i+1);
scanf("%s",temp->start_place);
printf("\t\t请输入第%d个航班目的地\n\t\t",i+1);
scanf("%s",temp->end_place);
printf("\t\t请输入第%d个航班起飞的时间\n\t\t",i+1);
scanf("%s",temp->start_time);
printf("\t\t请输入第%d个航班降落的时间\n\t\t",i+1);
scanf("%s",temp->end_time);
//getchar();
printf("\t\t请输入第%d个航班的座位\n\t\t",i+1);
scanf("%d",&(temp->total));
//getchar();
temp->left=temp->total;
//printf("\t\t你好\n");
p->next=temp;
p=temp;
//printf("\t\t你好\n");
p->next = NULL;
}
return pheadline;
}
int main()
{
Airline bb;
InitList_1(&bb);
Put_Flight_Information(3,bb);
return 0;
}
小修改了下 |