Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!caen!hellgate.utah.edu!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Subject: Re: fflush()? fscanf() fgets() problem. Organization: Lawrence Berkeley Laboratory, Berkeley References: <456@equinox.unr.edu> Message-ID: <13750@dog.ee.lbl.gov> X-Local-Date: Fri, 31 May 91 04:48:26 PDT Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Date: Fri, 31 May 91 11:48:26 GMT Distribution: na In article <456@equinox.unr.edu> whitbeck@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@ee.lbl.gov