From: cybpunk AT geocities DOT com (John G) Newsgroups: comp.os.msdos.djgpp Subject: Re: Flush stdin? Date: Thu, 28 Oct 1999 09:47:25 GMT Lines: 56 Message-ID: <38191ba8.20771109@news.ma.ultranet.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: jZ3uHrO6EqGgPU1st+C02AWjYuiX+xU9LpGsfYhzUj0= X-Complaints-To: abuse AT rcn DOT com NNTP-Posting-Date: 29 Oct 1999 01:53:52 GMT X-Newsreader: Forte Agent 1.5/32.451 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com >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. Thanks for that info. I know that the effect of fflush on the input stream is undefined, and that fflush is normally used when working with files, but I thought the reason it works in a MSVC console app and not a dos app is that windows creates it's own input buffer. Trust me, I am not a fan of MSVC, and would avoid it if I could >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. I will look into that, Thanks. >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. Okay, this is the reason I need to empty the buffer. Say I input a int with fscan then latter on input a character. Say the user doesn't follow directions and enters 1.5. Input stops at the period and leaves .5 in the buffer. Now when I use fscan to input a character it grabs the . out of the buffer and doesn't wait for input from the keyboard. Clearing out the buffer before the call to fscan solves this problem. int x; char c; fscan("%d", &x); . . fscan("%c", &c); I think I can solve my problem now, just letting you know why I am doing it. > >> 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. Thanks. I scaned the faq, I must have missed it. Thanks -John -- "Hallo. My name is Inigo Mantoya." "You killed my father." "Prepare to die." -Princess Bride