Mail Archives: djgpp/1999/07/07/01:37:07
> Think for a moment. What do you _mean_ by flushing a buffer. The action
> performed when you flush an output buffer is to complete output which you have
> already initiated. The data which is in the output buffer is written to the
> output device. Now you want to flush an input stream. This mean you want to
> complete pending input. But that is in fact not what most people mean when they
> ask this question. There is no intuitive "correct" action on "flushing" an
> input stream, and there is no defined behavior. Better you should ask Scott
> Nudds.
>
> 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?
main(){
char ch1, ch2;
printf("Enter a letter: ");
ch1 = getchar();
/* flush input here */
printf("Enter another letter: ");
ch2 = getchar();
}
- Raw text -