fflush()? fscanf() fgets() problem.

Chris Torek torek at elf.ee.lbl.gov
Fri May 31 21:48:26 AEST 1991


In article <456 at equinox.unr.edu> whitbeck at sanjuan.UUCP (Mike Whitbeck) writes:
>I have a problem using fscanf() and fgets() and was wondering
>if it had something to do with fflush() {I guess I just don't
>know what fflush() is for!}

Fflush() is for output files only (despite anything POSIX says to the
contrary; only output flush is reasonably portable).  It means `take
anything that I asked you to write earlier, and do your darnedest to
see that it gets written'.  Normally, a putchar, printf, fwrite, or
other output operation really means `do this eventually'.  Fflush means
`It is now ``eventually''.'

>I open a file
>	fp = fopen("file","r");
>and then I read some stuff
>	fscanf(fp,"%f\n",&fv);
>then later I try to suck in a line as a text string
>	fgets(str,n,fp);
>Elsewhere I have used fgets() to read in a line
>but here it fails! (gets only the first 'word' (whitespace
>delimited) from the line.

This suggests, but does not prove, that there is a bug in the
implementation you are using.  To prove it you must produce a complete
program (preferably as small as possible), not just code fragments.
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek at ee.lbl.gov



More information about the Comp.lang.c mailing list