I was trying to search for an answer for that but couldn't, hope someone can help. I have the following snippet of code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char c = '\0';
int error = scanf(" %c", &c);
// The user types now the following: A54fG6
while (error != EOF) {
printf("%c", c);
error = scanf(" %c", &c);
}
return 0;
}
Where the first comment is, the input buffer points at A. Then it goes into the while loop, prints the character 'A' and the second scanf advances the input buffer to point at 5. After the last iteration, when the printf printed '6' - the second scanf points at what character?
Or in different words, how can I know when the program finished reading the current input buffer and then do something before the scanf prompts the user for more characters?