scanf(“%c”) call seems to be skipped

Change

scanf("%c", &sex);

to

scanf(" %c", &sex);
       ^
      space

and

scanf("%c", &status);

to

scanf(" %c", &status);
       ^
      space

The problem is because of trailing newline characters after your second call to scanf(). Since it is of %d type specifier, when you press Enter A newline character ( '\n' ) is left in the stream and the next scanf() tries to read that newline character, and thus, it seems as though it just skipped input, but in fact, it read the newline character.

So, the newline character is stored in the variable sex, and thus, it skips asking you for input for that variable.

Leave a Comment