|
|
用c语言做一个航空售票系统,初有眉目。但有一问,请大家在程序中找到注释“为什么这里必须有个printf,否则程序无法继续运行??”这一行帮我分析一下。真的很奇怪,为什么没有这个printf,程序就陷入僵死状态?谢谢谢谢!
#define NULL 0;
typedef struct GUinform
{
char name[100];
int sex;
char adress[100];
long int phone;
int senum;
struct GUinform *next;
}GUinform,*guinform;
typedef struct Flight
{
char FLightname[100];
int canseated;
guinform guest;
int money;
struct Flight *next;
}Flight,*flight;
void creatFlight(flight *head,int *fltitle)/*fltitle represnts the arrange in order*/
{
int i, boo;
flight p,q;
(*fltitle)=0;
(*head)=(Flight *)malloc(sizeof(Flight));
((*head)->next)=NULL;/*why is it so nessary?*/
q=(*head);
do{
p=(Flight *)malloc(sizeof(Flight));
printf("Input Flight Class name:\n");
scanf("%s",&p->FLightname);
printf("How many can seated?\n");
scanf("%d",&p->canseated);
q->next=p;
q=p;
q->next=NULL;
(*fltitle)++;
printf("continue? 1.yes/2.no \n");
scanf("%d",&boo);}
while(boo==1) ;
}
void printFlightname(flight head)
{
int i=1;
flight p;
p=head->next;
while(p)
{printf("%d.%s\n",i++,p->FLightname);p=p->next;}
}
void spanclass(flight *head,flight *p,int *fltitle)
{
flight hhead;
int i,chonum;
p=head;
hhead=*head;
printFlightname(hhead);
printf("Input your choice:");
scanf("%d",&chonum);
for(i=1;i<=chonum;i++)(*p)=(*p)->next;
return;
}
void creatGUinform(flight *p,int *money,int *senum)
{ int i;
guinform r,s;
(*p)->money=(*money);
s=(*p)->guest;
while(s->next) s=s->next;
r=(guinform)malloc(sizeof(GUinform));
r->senum=*senum;
printf("input the guest's information below:\n");
printf("Name:");
scanf("%s",&r->name);
printf("Sex:1.male 2.female");
scanf("%d",&r->sex);
printf("Adress:");
scanf("%s",&r->adress);
printf(" hone:");
scanf("%ld",&r->phone);
r->senum++;
(*senum)=r->senum;
(*p)->money++;
printf("\n\n\nCheck the information:\n");
printf("Name: %s\n",r->name);
if(r->sex==1)
printf("Sex: male\n");
else if(r->sex==2)
printf("Sxe: female\n");
printf("Adress: %s\n",r->adress);
printf("Phone: %ld\n",r->phone);
printf("Serial Number: %d\n",r->senum);
printf("Please Remeber the Serial Number firmly,it's useful when you use back ticket system.\n");
printf("The Serial Number is: %d\n",r->senum);
s->next=r;
s=r;
s->next=NULL;
}
void buyticket(flight *head,flight *p,int *fltitle,int *money,int *senum)
{
int boo;
spanclass(head,p,fltitle);
printf("aa\n"); /*为什么这里必须有个printf,否则程序无法继续运行??*/
do
{
creatGUinform(p,money,senum);
printf("continue? 1.yes/2.no \n");
scanf("%d",&boo);
}
while(boo==1);
}
void backticket(flight *head,flight *p,int *fltitle,int *money)
{
int senum,i;
guinform r,s;
(*p)->money=(*money);
spanclass(head,p,fltitle);
printf("Input your serial number:\n");
scanf("%d",&senum);
r=(*p)->guest;
for(i=0;i<=senum-1;i++) r=r->next;
s=r->next;
r->next=s->next;
free(s);
(*p)->money--;
}
main()
{
int senum=0;
flight head,p;
int money,fltitle;
creatFlight(&head,&fltitle);
buyticket(&head,&p,&fltitle,&money,&senum);
getch();
} |
|