I'm a complete beginner in C programming and I have a question. I'll bring a simple code as an example:
#include <stdio.h>
int main( void )
{
int x;
printf( "Please type the number 10." );
scanf( "%i
", &x );
if ( x == 10 )
printf( "Thank you!
" );
return 0;
}
As expected, when I compile and run this program, my terminal displays the message:
"Please type the number 10."
Then it waits for input, so I type the number it asks for (10), and press ENTER. The problem is that after I press ENTER once, it moves to a new line and waits for more input. Only after typing 10 and pressing ENTER again does it actually move on (... to display "Thank you!").
So it appears that I have to press ENTER twice for my input to be accepted. Does anyone know why this happens?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…