delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/04/11:14:35

To: ronis AT onsager DOT chem DOT mcgill DOT ca (David Ronis)
Cc: pjones AT acs DOT bu DOT edu, djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: bug in scanf() really in fflush(stdin)
Date: Sun, 04 Sep 94 15:32:31 +0200
From: eliz AT is DOT elta DOT co DOT il

> 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).

According to ANSI C standard, fflush() has no defined effect on input
streams (e.g., see P.J.Plauger "The Standard C Library").  It is true
that on Unix it usually removes all pending input, but that behavior
is not universal across other OS's and should not be relied upon.
The portable way to go is either gets() or scanf("%*[^\n]\n").

	Eli Zaretskii

- Raw text -


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