Mail Archives: djgpp/1999/10/28/17:35:10
On Wed, 27 Oct 1999 cybpunk AT geocities DOT com wrote:
> In my 'C' class we use MS VC which will
> clear the input buffer with fflush(stdin), but djgpp (I believe due to
> the os) won't.
DJGPP's fflush doesn't empty the stdin buffer, but that has nothing to
do with the OS. The ANSI C Standard says that the effect of fflush on
input streams is ``undefined'' (which is the Standard's word for
``anything can happen''). So those who use the non-standard behavior
of MSVC write non-portable programs. You should tell them to read the
Standard more closely.
> Is there a alternative
> function to do this, provided with djgpp, or should I write my own.
If you do an fseek on stdin with large enough 2nd argumrnt, it will
automatically throw away the buffered characters. This *is* portable
behavior, so you should be able to use it with MSVC as well.
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.
> The second thing I need to do is have a
> #ifdef statement that will detect the djgpp compiler so I can define
> flush according to the compiler building the source.
This is in the DJGPP FAQ, see section 8.6 there.
- Raw text -