Trying to get some values to a struct. When I run the code, everything works perfectly except for the Gender values. For some reason that whole scanf just gets skipped over. In the command prompt it looks like this.
Please provide the student's first name: (user enters "John" and presses enter)
Please provide the student's first name: (user enters "Doe" and presses enter)
Please provide the student's gender (M/F): (can't input anything, no line skip) Please provide the student's age: (input)
etc.
I don't know if this could be a problem with another portion of the program, but I can edit in the whole thing if the problem isn't within this chunk of code.
if (option == 2){
i=i+1;
printf("Please provide the student's first name: ");
scanf("%s", roster[i].firstname);
printf("Please provide the student's last name: ");
scanf("%s", roster[i].lastname);
printf("Please provide the student's gender (M/F): ");
scanf("%c", &roster[i].gender);
printf("Please provide the student's age: ");
scanf("%i", &roster[i].age);
printf("Please provide the student's weight (In pounds): ");
scanf("%i", &roster[i].weight);
printf("Please provide the student's height (In inches): ");
scanf("%i", &roster[i].height);
}
" %c"
to skip white space before reading a non-space character. – Jonathan Lefflerfgets()
,strchr()
,strtok()
, etc. – user529758scanf()
is a fiendishly difficult function to use completely correctly. – Jonathan Leffler