The reason behind this is the newline \n
character left behind by previous scanf
, when pressing Enter key, for the next read of scanf
. When the statement
scanf("%c", &ch);
executed then it reads that \n
left behind by the previous scanf
.
To eat up this \n
you can use a space before %c
specifier. A space before the %c
specifier is able to eat up any number of white-space characters.
scanf(" %c", &ch);
^ a space