Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!alliance!darwinl From: darwinl@alliance.uucp (Darwin Ling) Subject: Re: fflush()? fscanf() fgets() problem. Message-ID: <1991Jun4.162558.18989@alliance.uucp> Organization: Alliance Technologies, Inc. References: <456@equinox.unr.edu> Distribution: na Date: Tue, 4 Jun 91 16:25:58 GMT 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!} > >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. >As a workaround I use a loop > for (...) { > fscanf(fp,"%s",dummy); > strcat(line," "); > strcat(line,dummy); > } >ICK! > >What's going on here? Is fscanf() known to mess up fgets()? or >is this unique to me? [I am using a SUN 3/80]. > >HELP! One possible problem is that your buffer's size , namely str's size, may not be big enough to store all the characters that you read from the file... Make sure you have allocated enough memory for str... ------------------------------------------------------------------ Darwin Ling Alliance Technologies , Inc Advanced Development group uunet : uunet!alliance!darwinl ------------------------------------------------------------------