Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.xenix Subject: Re: NEED HELP: fread, fwrite, fseek, ftell Keywords: AAAAAAAAARRRRRGGGHHH Message-ID: <2445@solo3.cs.vu.nl> Date: 3 May 89 03:34:59 GMT References: <7327@mrspoc.UUCP> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 26 itkin@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@bilpin) |maart@cs.vu.nl, mcvax!botter!maart