Problems with character input using scanf()

You don’t handle the newline. The %c specifier doesn’t skip blanks. Try:

scanf(" %c", &newChar);
    /* ^ <-- Makes `scanf` eat the newline. */

Or maybe add an explicit test.

scanf(...);
if (newChar == '\n')
    continue;

Leave a Comment