NEED HELP: fread, fwrite, fseek, ftell
Maarten Litmaath
maart at cs.vu.nl
Wed May 3 13:34:59 AEST 1989
itkin at mrspoc.UUCP (Steven M. List) writes:
\...
\ byteswritten = fwrite (outbuf, sizeof (char), bytesread, swabfile);
\...
\ bytesread = fread (inbuf, sizeof (char), sizeof inbuf, swabfile);
RTFM (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 [...] :-(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Solution: insert
fseek(swabfile, ftell(swabfile), 0);
At first sight this looks like a no-op, but there are some `interesting'
side-effects...
What to do if you f*ck things up? Just put it in the FM: it's a feature!
(Which will live on forever.)
BTW, whom can we sue for this? :-)
--
"If it isn't aesthetically pleasing, |Maarten Litmaath @ VU Amsterdam:
it's probably wrong." (jim at bilpin) |maart at cs.vu.nl, mcvax!botter!maart
More information about the Comp.unix.xenix
mailing list