Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: problem with fread/fwrite Keywords: fread, fwrite, file pointers Message-ID: <14384@smoke.brl.mil> Date: 7 Nov 90 12:05:56 GMT References: <402@bally.Bally.COM> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 15 In article <402@bally.Bally.COM> siva@bally.Bally.COM (Siva Chelliah) writes: - fp = fopen("temp.dat","r+b"); - fread(tbuf,sizeof(tbuf),1,fp); - fwrite(buf,sizeof(buf),1,fp); -line 0line 1line 2line 3line 4line 0line 4 -Can you believe this? Sure. -When I used fseek before fwrite, it worked. I do not remember reading -anywhere that I should do a fseek before fread/fwrite. The exact requirement is spelled out quite explicitly in the C standard, section 4.9.5.3. I won't bore you with the technical reasons, but this was not an oversight nor necessarily sloppiness on the part of your C vendor.