delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/07/07:15:33

From: DavMac AT iname DOT com (Davin McCall)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Flushing input stream?
Date: Wed, 07 Jul 1999 01:44:53 GMT
Organization: Monash Uni
Lines: 42
Distribution: world
Message-ID: <3782afa8.1319553@newsserver.cc.monash.edu.au>
References: <37819F79 DOT 72629349 AT singmail DOT com> <3781B0AF DOT 8905D645 AT earthlink DOT net> <37820CEB DOT 3832DCC1 AT singmail DOT com>
NNTP-Posting-Host: damcc5.halls.monash.edu.au
X-Trace: towncrier.cc.monash.edu.au 931311874 29536 130.194.198.138 (7 Jul 1999 01:44:34 GMT)
X-Complaints-To: abuse AT monash DOT edu DOT au
NNTP-Posting-Date: 7 Jul 1999 01:44:34 GMT
X-Newsreader: Forte Free Agent 1.1/32.230
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Input is always buffered up to a single new-line character. Therefore,
if you read everything up to and including the first newline in the
input, you will clear the buffer.

The only case where you can't really do this is when the buffer is
already clear (as trying to read from the buffer would wait for
further input)... You would have to check if the buffer was empty, but
I'm not sure if that's possible.

With care you can avoid the situation of trying to clear an already
empty buffer.

Davin.

On Tue, 06 Jul 1999 22:04:27 +0800, Chih Hui <wenzh AT singmail DOT com>
wrote:

>> If you mean "read characters until an end-of-line is read", then you obviously
>> have the answer stated in your question, and no further answer is required.
>> 
>
>No, I mean to clear the input stream of any characters. For example,
>when I run
>the code below, I enter 'A' at the first prompt. getchar() would
>correctly get
>the letter 'A', but the second getchar() would simply get the newline
>character 
>leftover from the first getchar(). 
>
>In Turbo C, a convenient, though non-standard, way is to fflush(stdin),
>which will
>discard all the pending characters in the standard input. How do I
>achieve this in
>DJGPP? 
>
>Thanks. 
>
>PS. Who is Scott Nudds?

__________________________________________________________
       *** davmac - sharkin'!! davmac AT iname DOT com ***
my programming page: http://yoyo.cc.monash.edu.au/~davmac/

- Raw text -


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