Mail Archives: djgpp/1999/07/07/07:15:33
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 -