fseek doesn't work properly

Conor P. Cahill cpcahil at virtech.UUCP
Fri Oct 20 12:03:53 AEST 1989


In article <496 at his.UUCP>, jonas at his.UUCP (Jonas Mellin) writes:
> The problem:
> 	fseek moves the filepointer to beginning of the file
> 	regardless of the parameters 
> Question:
> 	Does anyone else have this problem?


>     fseek(fp,(long)i*sizeof(a),0);
>     /* fseek(fp,(long)-sizeof(a),1); */
>     fwrite(&a,sizeof(a),1,fp);
>     fread(&a,sizeof(a),1,fp);


The problem probably is that you are using both the fread and fwrite
immediatly after each other.

My trusty manual specifies (on fopen(3s)):

	When a file is opened for update, both input and output may be
	done on the resulting stream.  However, output may not be directly 
	followed by input without an intervening fseek, or rewind.....

RTM.


-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list