Why doesn’t getchar() wait for me to press enter after scanf()?

Your scanf only ate the number but not the trailing newline. Putting a newline or white space after the %d will then give you the opposite problem, reading too far.

This is why people don’t like scanf.

I would suggest reading an actual line (use fgets(3)) and then using sscanf() to scan the string.

Leave a Comment