I'm doing my assignment, a hotel booking system. In my cancel booking part, I'm getting an error:
Exception thrown at 0x00007FFA68272BE7 (ucrtbased.dll) in assignment 2.0.exe: 0xC0000005: Access violation reading location 0x0000000000000001.
I have removed the printf and file opening and closing at the point where I'm getting this error, but I can still see all the printfs . The part where it gets stuck is when i ask user to give a reason for cancellation.
I removed that part of code, and wrote printf("thankyou")
but that doesn't appear. Yet the other printf I used before still appears on screen
void cancelBooking()
{
FILE* bookf; //file with booked room details
FILE* tempf;
char id[20];
int cancel = 0;
struct book b;
int r;
system("cls");
//cleaning up/ flush
while ((getchar()) != '\n');
printf("\n----- BOOKING CANCELLATION ------");
printf("\n to cancel, enetr your user ID for verification: ");
gets(id);
//checking if user id matches
if (strcmp(id, logged_in_user) == 0)
{
printf("\n user identified ");
//to view booked room status
view_status();
printf("\n------------------------------------------------------------------------------------");
//cleaning up/ flush
while ((getchar()) != '\n');
printf("\n enter your room no that you want to cancel: ");
scanf("%d", &cancel);
bookf = fopen("booked", "r");
tempf = fopen("tempFile", "w");
while (fread(&b, sizeof(b), 1, bookf))
{
r = b.roomNo;
if (r != cancel)
{
fwrite(&b, sizeof(b), 1, tempf);
}
}
fclose(bookf);
fclose(tempf);
//cleaning up/ flush
while ((getchar()) != '\n');
bookf = fopen("booked", "w");
tempf = fopen("tempFile", "r");
while (fread(&b, sizeof(b), 1, tempf))
{
fwrite(&b, sizeof(b), 1, bookf);
}
fclose(bookf);
fclose(tempf);
printf("\n BOOKING CANCELLED \n");
//cleaning up/ flush
while ((getchar()) != '\n');
printf("\n thankyou");
//going back to eithwr bookig menu or main menu
going_back();
}
else
{
//cleaning up/ flush
while ((getchar()) != '\n');
while (strcmp(id, logged_in_user) != 0)
{
printf("\n -- non user cannot cancel booking -- ");
printf("\n taking you back to BOOKING MENU");
system("cls");
display_booking_menu();
}
}
//cleaning up/ flush
while ((getchar()) != '\n');
}
I expect the code to move to "going back to main menus" but it is stuck at "thankyou" and wont move.
User contributions licensed under CC BY-SA 3.0