Reputation: 35285
Here's the statement:
int i;
scanf("%d ",&i);
Why does the space at the end of the format string causes scanf to accept two inputs instead of 1?
Upvotes: 2
Views: 188
Reputation: 21597
The space at the end of the format string tells scanf to eat whitespace after the first integer. It's not actually accepting a second input. When you do enter a second value, scanf sees that the whitespace is finished it returns, storing the first integer into your variable i. The "second input" is still in the standard input stream.
Upvotes: 4