Mail Archives: djgpp/1999/03/25/10:41:45
In article <36FA478D DOT 54A07B69 AT mbox2 DOT singnet DOT com DOT sg> you wrote:
> I was doing my C++ homework.
Just as a sidenote: there's nothing C++-specific in your question
at all. It's all about plain C.
> I compile the file and no error was found. But in my program, there
> is a fflush(stdin); to flush away the buffered input of
> scanf();. But the char enter key was not flush away when using DJGPP
> but was flush away when using borland C. May i know how to solve
> this problem?
The real problem is in your belief that fflush(stdin) does anything
predictable, which it doesn't. It's one of the typical 'DOSisms' you
find in badly written books about C and/or C++.
The proper method to flush an input stream is to write a small loop
that behaves like this:
while ((dummy = getchar()) != EOF)
; /* do nothing, just loop */
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -