delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/25/10:41:45

Date: Thu, 25 Mar 1999 16:41:32 +0100
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Message-Id: <199903251541.QAA16511@acp3bf.physik.rwth-aachen.de>
To: djgpp AT delorie DOT com
Subject: Re: Some questions??
Newsgroups: comp.os.msdos.djgpp
Organization: RWTH Aachen, III. physikalisches Institut B
X-Newsreader: TIN [version 1.2 PL2]
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019