From: Chih Hui Newsgroups: comp.os.msdos.djgpp Subject: Re: Flushing input stream? Date: Tue, 06 Jul 1999 22:04:27 +0800 Organization: Subscriber of Pacific Internet Lines: 42 Message-ID: <37820CEB.3832DCC1@singmail.com> References: <37819F79 DOT 72629349 AT singmail DOT com> <3781B0AF DOT 8905D645 AT earthlink DOT net> NNTP-Posting-Host: ppp244.dyn95.pacific.net.sg Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; I) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > 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(); }