Mail Archives: djgpp/1999/10/31/08:31:40
On Thu, 28 Oct 1999, John G wrote:
> >But a better solution would be to rewrite your code so that it doesn't
> >*need* to empty the input buffer at all. Unfortunately, you didn't
> >provide any details about why do you need to empty stdin, so it is
> >impossible to give a more specific advice.
>
> Okay, this is the reason I need to empty the buffer. Say I input a
> int with fscan then latter on input a character.
That's your problem, right there: using `fscanf' for free-format input
is a Bad Idea (tm). Use `fgets', and then process the string
yourself, either with `sscanf' or with `strtol'. The latter is
generally easier, since it returns a pointer to the unprocessed part
of the string, which makes it easier to see what character confused
it.
- Raw text -