PDA

View Full Version : C character scanf



shashanksingh
June 3rd, 2012, 04:54 PM
#include<stdio.h>

int main()
{
int i;
char k[10];

for(i=0;i<2;i++)
{
scanf("%c",&k[i]);
printf("%c",k[i]);
}

return 0;
}
When I execute the above code, why does it not take input twice? It just prints it once and exits. It somehow takes "return" as the second input I believe

dwhitney67
June 3rd, 2012, 05:09 PM
Twice, huh?

How many keys on your keyboard did you press? Think carefully.


P.S. Your conclusion is correct.