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

Mike Whitbeck whitbeck at sanjuan.wrcr.unr.edu
Fri May 31 16:44:57 AEST 1991


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!



More information about the Comp.lang.c mailing list