Clarification needed regarding getchar() and newline

Yes, you have to consume newlines after each input:

char1 = getchar();
getchar(); // To consume `\n`
char2 = getchar();
getchar(); // To consume `\n`

This is not compiler-dependent. This is true for all platforms as there’ll be carriage return at the end of each input line (Although the actual line feed may vary across platforms).

Leave a Comment