problem with fread/fwrite
Doug Gwyn
gwyn at smoke.brl.mil
Wed Nov 7 23:05:56 AEST 1990
In article <402 at bally.Bally.COM> siva at 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.
More information about the Comp.lang.c
mailing list