Article View: comp.lang.c.moderated
Article #2599Re: fflush(stdin) - not guaranteed to work?
From: GHouck
Date: Mon, 15 Apr 1996 18:12
Date: Mon, 15 Apr 1996 18:12
26 lines
1063 bytes
1063 bytes
gohel@csee.usf.edu (Himanshu Gohel) wrote:
[snip]
>
>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:
>
Himanshu,
I would recommend the following:
char *pnl;
char inpBuf[MAXBUF];
FILE *strm;
...
...
while( fgets(inpBuf,sizeof(inpBuf),strm) ) {
...
if( (pnl=strchr(inpBuf,'\n')) ) /* truncate the newline */
*pnl = '\000';
...
sscanf( inpBuf,... );
...
}
Yours, Geoff Houck
Technical Details
Message-ID:
<4ku3hq$52g@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4ksjpn$rjt@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: GHouck <hksys@teleport.com> Newsgroups: comp.lang.c.moderated,comp.lang.c Subject: Re: fflush(stdin) - not guaranteed to work? Date: 15 Apr 1996 13:12:10 -0500 Organization: systems hk Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4ku3hq$52g@solutions.solon.com> References: <4ksjpn$rjt@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Mailer: Mozilla 1.22 (Windows; I; 32bit)