To directly answer why the 3rd and every other scan "skips", it is the way scanf()
and the %c
format works. When there is a call to scanf()
, you typically have to press enter to "submit" the input. Consequently that inserts a newline character into the stdin
stream.
When the previous float scan got inputted, the newline is still left in the stream. When the character scan gets reached, that remaining newline character is read in since it fits effectively "skipping" the call.
You should use fgets()
with sscanf()
as codaddict suggests.
But as a quick fix, you could try adding a call to getchar()
after the float scan to consume that newline character from the stream.
edit:
You're saying this doesn't work? (assuming you input the correct kinds of values, one per scanf call)
main()
{
char c[5];
float q[5];
int i;
for(i=0;i<5;i++)
{
printf("\n%d ",i);
scanf("%c",c+i);
scanf("%f",q+i);
getchar();
}
}