1
for(i=0;i<requestnum;i++)
{
   bookcount++;
   printf("\n\nEnter Booking Request #%d", bookcount);
   printf("\nLast Name:");
   fgets(OneClient[i].LastName,100,stdin);
   if(!strcmp(OneClient[i].LastName, "\n"))
{
    printf("Processed %d successful requests out of %d submitted 
    requests.\nGenerating management report.\nThank you for using the hotel 
    reservation system.\nBye!",succescount, bookcount);
    exit(1);
}
printf("First Name:");
scanf(" %s", OneClient[i].FirstName);
}

The fgets does its work in the first loop, but when the second loop occurs, it scans and stores a blank character and doesnt wait for a user input, I used fgets because I need to terminate the loop when a blank is entered by the user. Help fix my problem please?

  • It is not quite the same situation as the duplicate but is for the same reason. It's a bad idea to mix different input methods. – Weather Vane Feb 26 '19 at 10:29

1 Answers1

1

fgets is reading \n left out by scanf in the stream.

Just replace scanf with fgets.

for(i=0;i<requestnum;i++)
{
   bookcount++;
   printf("\n\nEnter Booking Request #%d", bookcount);
   printf("\nLast Name:");
   fgets(OneClient[i].LastName,100,stdin);
    ......
    .....
   printf("First Name:");

   /*Assumed FirstName is not pointer*/
   fgets(OneClient[i].FirstName, sizeof(OneClient[i].FirstName), stdin);
}
kiran Biradar
  • 12,700
  • 3
  • 19
  • 44