#include
int main ()
{
char loop=\'y\';
while(loop != \'n\') {
printf(\"loop? \");
scanf(\"%c\", &loop);
if(loop
Make sure the scanf
discards the newline. Change it to:
scanf(" %c", &loop);
^
One solution can be the use fflush(stdin)
after the scanf()
statement to clear the input buffer.
You probably had to enter a newline so the input goes to your program, right? The second time your loop executes it reads that newline character, which was "waiting" to be read and automatically exits the loop ('\n' != 'y'
). You can make scanf ignore whitespace by using this format string instead:
" %c"