Date: Thu, 28 Oct 1999 19:29:50 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: cybpunk AT geocities DOT com cc: djgpp AT Delorie DOT com Subject: Re: Flush stdin? In-Reply-To: <7v82k1$opj$1@nnrp1.deja.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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.