我想顯示鏈接列表中的席位的可用性,但我不知道chekcavailability()
中的邏輯不起作用。如何檢查C代碼鏈接列表中的可用性席位
第一次輸入沒問題,第二次輸入時我輸入了相同的值,表示座位已經被拿走並返回到特定的功能。
但是當我再次輸入可用的不同值時,它會給我一個錯誤。
請幫助謝謝。
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define A 20
struct passenger
{
char name[20];
char booking_id[20];
char passno[20];
char seatno[20];
struct passenger *next;
}*start,*curr;
void datainput(), savefile(), loadfile(), checkavailability(), validationseat();
int main()
{
void reserve_seat(), cancel_seat(), modify_seat(), display_layout(), exit();
int choice;
start=curr=NULL;
do
{
system("cls");
printf("\n\n*************************************************");
printf("\n\n********AIRLINE RESERVATION MENU*****************");
printf("\n\n*************************************************");
printf("\n\n\t\t* 1. Reserve seat *");
printf("\n\n\t\t* 2. Modify seat *");
printf("\n\n\t\t* 3. Cancel seat *");
printf("\n\n\t\t* 4. Display seat layout*");
printf("\n\n\t\t* 5. Exit *");
printf("\n\n*************************************************");
printf("\n\n\n\n\t\t Enter your choice: ");
scanf("%d",&choice);fflush(stdin);
switch (choice)
{
case 1:
reserve_seat();
break;
case 2:
modify_seat();
break;
case 3:
cancel_seat();
break;
case 4:
display_layout();
break;
case 5:
{
exit();
break;
}
default:
printf("invalid choice!!, please try again");
}
getch();
}while (choice != 5);
}
void datainput()
{
printf("\n\t\t enter your booking ID: ");
gets(curr->booking_id); fflush(stdin);
printf("\n\t\t enter your seat number: ");
gets(curr->seatno); fflush(stdin);
printf("\n\t\t Enter Name: ");
gets(curr->name); fflush(stdin);
printf("\n\t\t Enter Passport Number: ");
gets(curr->passno); fflush(stdin);
}
void reserve_seat()
{
curr=start;
checkavailability();
if(start==NULL)
{
start=curr=(struct passenger *)malloc(sizeof(struct passenger));
datainput();
curr->next=NULL;
printf("\n\t data has been recorded");
return;
}
while(curr->next=NULL)
curr=curr->next;
curr->next=(struct passenger *)malloc(sizeof(struct passenger));
curr=curr->next;
datainput();
curr->next=NULL;
printf("\n\t data has been recorded");
void checkavailability()
{
int i;
char cmp3[20];
printf("select your seat(1-20)");
gets(cmp3);fflush(stdin);
while(curr)
{
if (strcmp(curr->seatno, cmp3)==0)
{
printf("Seat has been taken\n");
checkavailability();
}
else
{
break;
}
}
printf("seat available");
return;
}
花時間編輯您的帖子,然後發佈。好 。糾正Tom指出的所有錯誤。然後發帖 – 2016-06-07 09:21:31