main()
{
int d,a;
printf("Enter the digit :");
scanf("%d",&d);
printf("Enter another digit :");
scanf("%d",&a);
}
output: Enter the digit : 10 Enter the another digit:10
main()
{
int d;
char a[10];
printf("Enter the digit :");
scanf("%d ",&d);
printf("Enter another digit :");
scanf("%s ",a);
}
output:
Enter the digit : 10
waiting for stdin
Can anyone explain the difference between scanf("%d",&a) and scanf("%d ",&a)? Why does adding a space in the scanf statement cause it to wait of stdin?
A whitespace in a scanf format string matches any whitespace character, not only space, even multiple times, so if you press enter, it is a part of the matched string. If you press Ctl+D it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With