🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2595

Re: fflush(stdin) - not guaranteed to work?

#2595
From: P.Bennett
Date: Mon, 15 Apr 1996 18:08
24 lines
1734 bytes
In article <4ksjpn$rjt@solutions.solon.com>, gohel@csee.usf.edu writes...
>In Paul S. Wang's "Introduction to ANSI C on UNIX" he says that
>the fflush() function was "not intended to control input buffering"
>on page 266.

I believe the C standard agrees with him.  :-)

>What is the best way to get rid of the '\n' from the input buffer after
>a scanf() statement?  In the same book on page 263 I've seen the following
>format used in an fscanf() format specifier:

don't use scanf() for direct user input - besides the "leftover '\n'" problem,
it can cause great grief if the user enters a letter when scanf() is expecting
a number.

A better input procedure is to get a line with fgets(), then parse it with
sscanf(), strtok(), or other functions.

Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
Internet: bennett@triumf.ca         | of one another only when one can be
Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
Technical Details
Message-ID: <4ku3a3$4u9@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4ksjpn$rjt@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: bennett@erich.triumf.ca (P.Bennett)
Newsgroups: comp.lang.c.moderated,comp.lang.c
Subject: Re: fflush(stdin) - not guaranteed to work?
Followup-To: comp.lang.c.moderated,comp.lang.c
Date: 15 Apr 1996 13:08:03 -0500
Organization: TRIUMF: Tri-University Meson Facility
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4ku3a3$4u9@solutions.solon.com>
References: <4ksjpn$rjt@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com