So, I've got the following code (C):
char c = getc(in);
if (c == '(')
...
if (c == '%')
...
if (isdigit(c))
{
int n;
ungetc(c, in);
scanf("%i", &n);
...
}
Everything is all fine and dandy when I'm reading in input from stdin but, when reading in input from from a file, the call to scanf
does not terminate.
I added some code around the call to see what's going on before the call to scanf
. One such instance is
c = '0'
- the character right after
c
is)
Is the buffer not flushing after ungetc
or something? What might be happening, that it works fine when the input is stdin
but not when its a file? (I'm not that familiar with IO in C).
edit: Should have used fscanf
... boy is my face red.