www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/31/08:31:40

Date: Sun, 31 Oct 1999 09:47:38 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: John G <cybpunk AT geocities DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Flush stdin?
In-Reply-To: <38191ba8.20771109@news.ma.ultranet.com>
Message-ID: <Pine.SUN.3.91.991031094717.2988P-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Thu, 28 Oct 1999, John G wrote:

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

That's your problem, right there: using `fscanf' for free-format input
is a Bad Idea (tm).  Use `fgets', and then process the string
yourself, either with `sscanf' or with `strtol'.  The latter is
generally easier, since it returns a pointer to the unprocessed part
of the string, which makes it easier to see what character confused
it.

- Raw text -


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