You may be entered a "Return" key just after a character.
This means a line-feed character also has been supplied to the program. That's what happened to the program.
To avoid this use fgets() and sscanf().
#include<stdio.h>
int main()
{
int i;
char a[10], buf[10];
for(i=0; i<5; i++)
{
printf("%d) Enter a character: ", i);
fflush(stdout);
fgets(buf, 10, stdin);
sscanf(buf, "%c", &a[i]);
}
for(i=0; i<5; i++)
{
printf("%d) Entered character: %c\n", i, a[i]);
}
}
Output:
0) Enter a character: a
1) Enter a character: b
2) Enter a character: c
3) Enter a character: d
4) Enter a character: e
0) Entered character: a
1) Entered character: b
2) Entered character: c
3) Entered character: d
4) Entered character: e
fflush() in the code not necessary in unix like system.