delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/01/12:09:05

Date: Thu, 1 Sep 1994 10:48:00 -0400
From: pjones AT acs DOT bu DOT edu
To: djgpp AT sun DOT soe DOT clarkson DOT edu, ronis AT onsager DOT chem DOT mcgill DOT ca
Subject: Re: bug in scanf()

This is the correct behavior of scanf();  it will work that way on all
C compilers.

The problem with your test program is that when scanf() encounters an
illegal character according to its format specification, it will not
remove it from the input stream, so you are continually trying to scan
the same invalid string.  One way of fixing this would be to call
"fflush(stdin)" after when you scanf() has failed, or before every
scanf() call, whichever is more appropriate...

Hope this clears things up,

Peter Jones

- Raw text -


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