--- In [email protected], "Brett McCoy" <[EMAIL PROTECTED]> wrote:
>
> On Wed, Aug 6, 2008 at 12:20 PM, Bill Cunningham <[EMAIL PROTECTED]> wrote:
> 
> > If you've successfully flushed your output streams, that's
> > fine. If you haven't, then you run the risk of silent
> > truncation.
> >
> >    fclose(fp);
> >    fflush(fp);
> >
> > Is this what you are meaning ?
> 
> Other way around, you need to flush before closing.

You shouldn't need to fflush() before fclose():

"The  fclose()  function will flush the stream pointed to by fp
(writing any buffered output data using fflush(3)) and close the
underlying file descriptor."

(from the fclose() man page)

I believe Peter was just saying that if the fclose() fails and you
haven't done a fflush(), then you might lose some data that your
program has previously written to the file. But fclose() shouldn't
fail - if it does, then a fflush() would probably have failed as well.

John

Reply via email to