Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: fseek fread fwrite fflush Message-ID: <669@taumet.com> Date: 14 Apr 91 17:10:28 GMT References: <1991Apr13.003817.12434@watdragon.waterloo.edu> <1991Apr12.194547.18080@hellgate.utah.edu> Organization: Taumetric Corporation, San Diego Lines: 26 tmurphy%peruvian.utah.edu@cs.utah.edu (Thomas Murphy) writes: >In article <1991Apr13.003817.12434@watdragon.waterloo.edu> amewalduck@trillium.waterloo.edu (Andrew Walduck) writes: >>I've got a question about fseek, fread, fwrite and fflush.... >>Is it necessary to do the following? >>fflush(fp); >>fseek(fp....); >>fwrite(fp...); >You are always safest if you flush streams btwn io phases...this goes >for io to the console or to some file...thus if you have been reading >you should flush before writing and again before returning to reading >again and in addition flush before closing... Not quite true. The ANSI rules state that the effect of fflush() on a file whose last operation was a read are undefined -- an implementation is allowed to do bad things if you fflush() after an input operation. But you are guaranteed to be able to safely switch between reading and writing a file if you fseek() first -- even fseek() to the same position. For non-ANSI systems, you have to check the manual to see whether the fflush() is safe or required. -- Steve Clamage, TauMetric Corp, steve@taumet.com