scanf getchar function is skipped

Solution 1:

It's because scanf will leave a '\n' (endline) symbol in the input buffer. This symbol will be consumed by getchar at the first iteration of this while(1) loop.

Solution 2:

getchar() leaves a newline character in the input buffer which is read by the subsequent scanf().

You can use solve this by using a leading space in the scanf:

scanf(" %c ...", &c,..);

which tells the scanf to ignore all whitespace characters. Or use another getchar() right after the first getchar() to consume the newline.

Solution 3:

Just use another getchar() after the scanf() to consume the newline character.