i've narrowed the problem down to the strcpy part.. when trying this seperately, changing if(result==0) to if(result<0) fixes the problem, but why so? and even if i change it ti if(result<0) it doesn't work in my program..
here's the function that calls the problem function:
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include "custom.h"
extern struct SmokingPassenger Spassenger[12];
extern struct NonSmokingPassenger NSpassenger[6];
extern struct waitinglist waiting_list[9];
void main(void);
// Start of Option1_Reserve
void Option1_Reserve(void)
{
extern int ArrayNo;
extern int WLArrayNo;
extern int smoking_space;
extern int nonsmoking_space;
char name[25];
char choice_smoking;
char smoking_alt;
char temp[30];
int quit=0;
int loop=0;
// Enter name
system("cls");
printf("Please enter your name: ");
fflush(stdin);
scanf("%s", &name);
strupr(name);
// Smoking or non-smoking?
do {
printf("\nWould you prefer the (s)moking or the (n)on-smoking section?: ");
fflush(stdin);
scanf("%c", &choice_smoking);
choice_smoking=toupper(choice_smoking);
if (choice_smoking=='S')
{
if (smoking_space>0)
{
system("cls");
printf("An available seat in the smoking section has been allocated to you.\n");
printf("Your ticket has been printed out. Please take it.");
smoking_space--;
ReserveSeat(1,name);
printf("%s", &name);
getch();
main();
}
else if (nonsmoking_space>0)
{
system("cls");
printf("Sorry, there is no space in the smoking section.\n");
printf("However, there are seats in the non-smoking section, would you like to reserve a seat there? Y/N: ");
fflush(stdin);
scanf("%s", &smoking_alt);
smoking_alt=toupper(smoking_alt);
do {
loop=0;
if (smoking_alt=='Y')
{
system("cls");
printf("An available seat in the non-smoking section has been allocated to you.\n");
printf("Your ticket has been printed out. Please take it.");
nonsmoking_space--;
ReserveSeat(2,name);
getch();
main();
}
else if (smoking_alt=='N')
{
system("cls");
printf("Sorry, the flight is full. You will be put in the waiting list.");
strcpy(waiting_list[WLArrayNo].name,name);
strcpy(temp,"smoking");
strcpy(waiting_list[WLArrayNo].smoking,temp);
WLArrayNo++;
getch();
main();
}
else
{
printf("Please enter Y or N.");
}
} while (loop==0);
main();
}
else
{
printf("Sorry, the flight is full. You will be put in the waiting list.");
strcpy(waiting_list[WLArrayNo].name,name);
strcpy(temp,"smoking");
strcpy(waiting_list[WLArrayNo].smoking,temp);
WLArrayNo++;
getch();
}
quit=1;
}
else if (choice_smoking=='N')
{
if (nonsmoking_space>0)
{
system("cls");
printf("An available seat in the non-smoking section has been allocated to you.\n");
printf("Your ticket has been printed out. Please take it.");
nonsmoking_space--;
ReserveSeat(2,name);
getch();
main();
}
else if (nonsmoking_space>0)
{
system("cls");
printf("Sorry, there is no space in the non-smoking section.\n");
printf("However, there are seats in the smoking section, would you like to reserve a seat there? Y/N: ");
fflush(stdin);
scanf("%s", &smoking_alt);
smoking_alt=toupper(smoking_alt);
do {
loop=0;
if (smoking_alt=='Y')
{
system("cls");
printf("An available seat in the smoking section has been allocated to you.\n");
printf("Your ticket has been printed out. Please take it.");
smoking_space--;
ReserveSeat(1,name);
getch();
main();
}
else if (smoking_alt=='N')
{
system("cls");
printf("Sorry, the flight is full. You will be put in the waiting list.");
strcpy(waiting_list[WLArrayNo].name,name);
strcpy(temp,"smoking");
strcpy(waiting_list[WLArrayNo].smoking,temp);
WLArrayNo++;
getch();
main();
}
else
{
printf("Please enter Y or N.");
}
} while (loop==0);
main();
}
else
{
printf("Sorry, the flight is full. You will be put in the waiting list.");
printf("\nWould you prefer the (s)moking or the (n)on-smoking section?: ");
fflush(stdin);
scanf("%c", &temp);
strcpy(waiting_list[WLArrayNo].name,name);
strcpy(waiting_list[WLArrayNo].smoking,temp);
WLArrayNo++;
getch();
main();
}
quit=1;
}
else
{
printf("Please enter S for smoking or N for non-smoking.");
quit=0;
}
} while (quit==0);
}
and here's the problem function:
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include "custom.h"
extern struct SmokingPassenger Spassenger[12];
extern struct NonSmokingPassenger NSpassenger[6];
void ReserveSeat(int temp, char name[25])
{
int ArrayNo=0;
int repeat=1;
char empty[25];
int result;
if (temp=1)
{
for (ArrayNo=0;ArrayNo++;repeat=0)
{
result=strcmp(Spassenger[ArrayNo].name,empty);
if (result==0)
{
strcpy(Spassenger[ArrayNo].name,name);
repeat=0;
}
}
}
else
{
for (ArrayNo=0;ArrayNo++;repeat=0)
{
result=strcmp(NSpassenger[ArrayNo].name,empty);
if (result==0)
{
strcpy(NSpassenger[ArrayNo].name,name);
repeat=0;
}
}
}
}