Article View: gnu.gcc.help
Article #42792Re: gcc fflush(stdin) problem
From: Raik Hameister
Date: Mon, 23 Oct 1995 00:00
Date: Mon, 23 Oct 1995 00:00
21 lines
1083 bytes
1083 bytes
> I am using 2.7.0 of gcc. I am trying to fflush(stdin)
> but it is not working properly.
> int ReadNum(void)
> {
> int n; /* input number */
>
> printf("Enter an integer to be squared: ");
> scanf("%d", &n);
> fflush(stdin); /* advance buffer pointer past newline */
"fflush" with an Input-Stream?
fflush works fine only with an Output-Stream ala stdout, stderr...
see ANSI-C Doc or "man fflush".
Take a string-input over fgets,
errorhandling is easier than sledgehammer-function scanf.
eg.
int n=-1;
char is[100];
if( fgets(is,100,stdin) ) n=atoi(is);
Technical Details
Message-ID:
<2#5s-xks@maushro.baltic.de>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<DGpBAs.62E@boss.cs.ohiou.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,ac805b42612e8e71 X-Google-Attributes: gid11318c,public From: Raik_Hameister@maushro.baltic.de (Raik Hameister) Subject: Re: gcc fflush(stdin) problem Date: 1995/10/23 Message-ID: <2#5s-xks@maushro.baltic.de> X-Deja-AN: 118105391 references: <DGpBAs.62E@boss.cs.ohiou.edu> organization: Maus HRO BBS / Rostock, Germany / +49-381-696350 newsgroups: gnu.gcc.help x-mailer: Freedom of Maus, Version 0.70.2.8.00c/HRO