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);
  gets(name);

  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);
    }
  else
    {
      SeatArray[row-2][seat-63].name = name;
      SeatArray[row-2][seat-63].taken = 1;
    }

Recommended Answers

All 3 Replies

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

commented: helped, thanks +0

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()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.