Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: fseek doesn't work properly Keywords: fseek, C Message-ID: <1292@virtech.UUCP> Date: 20 Oct 89 02:03:53 GMT References: <496@his.UUCP> Organization: Virtual Technologies Inc Lines: 37 In article <496@his.UUCP>, jonas@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 | +-----------------------------------------------------------------------+