So I have a program that runs a loop in main to call functions to show all seats with their name and to reserve seats. My code works fine to reserve a seat. But when I reserve a second/third/fourth seat the name I enter for that seat overwrites the names for seats already reserved. Even if the seat is already occupied the name gets overwritten. Anyone know why?

char* name; //persons name
  char seat; //the seat they want
  char cr;
  int row = 0; //the row they want  

  printf("Enter the seat and name like this: 4B, Jason Gills\n");
  scanf("%d %c%c", &row, &seat, &cr);

  if(SeatArray[row-2][seat-63].taken == 1)
      printf("Seat %d%c is already taken. Please enter an available seat when making a reservation.\n", row, seat);
      SeatArray[row-2][seat-63].name = name;
      SeatArray[row-2][seat-63].taken = 1;

Edited by Firedown: n/a

6 Years
Discussion Span
Last Post by WaltP

You are setting the SeatArray name equal to pointer name, not copying the name. Use strcpy.

Edited by Momerath: n/a

Votes + Comments
helped, thanks

Thanks for pointing that out. Been a few months since I programed with c. Got it working.


Another problem. You have a pointer for name but you have no storage space. You must declare space to actually store the name.

And read this about gets()

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.