C char scanf

#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

1 Like

This program is working fine. it is reading input twice.

This program is reading input character by character. Make a note that both “Enter” and “white space” are character.

6 Likes

Yes this program is working fine. And as @jaikamal said that both “Enter” and “white space” are character you should make your observations again and also this program will not take return statement as second input as it is not a input function and the return statement is outside the braces of the for loop. You can learn more about loops in c HERE.

1 Like

“Enter” is also taken as input , add a space before %c when using scanf.

scanf(" %c",&k[i]);