Can someone please explain me why the scanf
behaves differently in these two programs. I have prepared a sample test program to demo it.
Program Version 1
#include <stdio.h>
int main()
{
int i;
char c;
for(i=0;i<4;i++)
{
scanf("%c",&c);
printf("%c",c);
}
return 0;
}
Program Version 2 (see scanf)
#include <stdio.h>
int main()
{
int i;
char c;
for(i=0;i<4;i++)
{
scanf(" %c",&c); //The only difference is space
printf("%c",c);
}
return 0;
}
In program 1 I can enter
a
b
c
d
But in program 2 I can only enter
a
b
Why?