Hi all!
I was experimenting a little with scanf. I am posting the code and the outputs I am having prolems understanding:
#include <stdio.h>
int main()
{
char a,b,c;
int d,e;
scanf("%c%c",&a,&b);//-------------------(1)
printf("%c %c\n\n",a,b);
scanf("%d%d",&d,&e);//-------------------(2)
printf("%d %d\n\n",d,e);
scanf("%c abc",&a);//--------------------(3)
printf("%c\n\n",a);
scanf("%c abcdefgh",&a);//---------------(4)
printf("%c\n\n",a);
getch();
return 0;
}
In (1):
Doesnt work. Scanf only takes one input. For (2), the same thing works. Why is it that it works for integers but not characters?
In (3):
Lets say I input 'm'. The subsequent printf prints nothing. After that, for scanf in (4) if I input 'k', then the subsequent printf prints 'm'. Why is that?
Thanks !