delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/01/15:13:17

Date: Thu, 1 Sep 1994 14:11:44 +0500
From: ronis AT onsager DOT chem DOT mcgill DOT ca (David Ronis)
To: pjones AT acs DOT bu DOT edu
Subject: Re: bug in scanf() really in fflush(stdin)
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

Hi Peter,

You are correct.  My test program works the same way under the
different OS's/Compiler.  When I include fflush(stdin), only djgpp
gives a problem. Thus the bug(?) isn't in scanf(), but is in
fflush(stdin).

Looking more carefully at the real code that generated the error, I
discovered that I'd been already been running fflush(stdin) after this
block of code exited (the code was initially developed under SUNOS, and
so I probably had to do this to avoid the problem in the first place).
Hence, any remaining input would be flushed (and is, except under
djgpp).

While I had programmed around the problem by using gets()/sscanf() much
like you suggested, in this part of my application, scanf() is really
much simpler.  For now the best suggestion I received is to clean up by
using scanf("%*[^\n]\n"), which works.

Thanks to all.

- Raw text -


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