#include<stdio.h>
int main()
{
char r[10];
char let;
int i;
for(i = 0; i < 10; i++)
{
printf("Enter a letter:");
scanf("%c",&let);
r [i]= let;
}
puts(r);
}
In the above code, on execution we r prompted to enter only five times.. Can anyone please tl me y it is so... Only using character array has this problem.
I am not a C guru but what I feel in the code portion of yours is that the newline ('\n') is also getting accepted as typed character. So if you see the output each digit is one below the other.
1
2
3
4
5
Try modifying the code by putting scanf("%c\n", &let);
You are reading char type. I'm preety sure you press enter after you input the character. scanf("%c", &let); read a char and only a char. If you input a char and enter then you have char enter in stream buffer and the next time scanf will be called will read the enter key from stream buffer.