delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/29/00:21:19

From: Damian Yerrick <DELCAPSyerricde AT pineight DOT 8mSOFTWARE DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Flush stdin?
Organization: Pin Eight Software <http://yerricde.tripod.com/binaries/>
Message-ID: <aQ4ZOPUNnvi=VFn1RZjihKytIU=r@4ax.com>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 991028192929 DOT 9453N-100000 AT is> <38191ba8 DOT 20771109 AT news DOT ma DOT ultranet DOT com>
X-Newsreader: Forte Agent 1.6/32.525
MIME-Version: 1.0
Lines: 23
X-Trace: /Kp2lrk7wyEGjutw20lsSXmwDZsCWxVEHI1voNmRrHr/8t/OwZwEhBATVFLvkKxJFzPeaUnGo/WT!It1+jEe2Ald8r4u3uoZVYKfGfOwhTNA8iNx7Vb+xjpkvEClVr7ro2kzUqTTtUJbMtw==
X-Complaints-To: abuse AT gte DOT net
X-Abuse-Info: Please be sure to forward a copy of ALL headers
X-Abuse-Info: Otherwise we will be unable to process your complaint properly
NNTP-Posting-Date: Fri, 29 Oct 1999 03:06:23 GMT
Distribution: world
Date: Fri, 29 Oct 1999 03:06:23 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Thu, 28 Oct 1999 09:47:25 GMT,
cybpunk AT geocities DOT com (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.  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.

I've always done my scanf()ing by combining gets() with sscanf(). It's
quite a bit safer, as you get a line at a time, similar to what is
done with "LINE INPUT string$" in some Basic dialects.

--
Damian Yerrick
Visit my web site: http://yerricde.spedia.net/

- Raw text -


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