[Courses] Re: [C] A clarification on fflush(stderr)

Sneha sneha at vit.ac.in
Fri Aug 9 08:34:03 EST 2002


Hi all :)

Laurel Fan's example was of gr8 help ...thank u....

#include<stdio.h>
main()
{
    char buff[BUFSIZ];
    setbuf(stderr,buff);
    fprintf(stderr,"stderr is buffered..........(1)\n");
    sleep(5);
    fprintf(stderr,"stderr is unbuffered........(1)\n");
    sleep(5);
    setbuf(stderr,buff);
    fprintf(stderr,"stderr is buffered..........(2)\n");
    sleep(5);
    fprintf(stderr,"stderr is unbuffered........(2)\n");
    sleep(5);
    setbuf(stderr,buff);
    fprintf(stderr,"stderr is buffered & flushed........(1)\n");
    fflush(stderr);
     sleep(5);
}        

** This code makes me think a lot...
if I use setbuf, stderr becomes buffered, the next statement without setbuf is bringing stderr to itz normal unbuffered state...so, I believe fflush is not an essential statement to be added when stderr is used, unless or otherwise if stderr is made buffered using setbuf ...which I have specified in my last statements....

happy day!!!
ba bye
friendly
sneha :o)

Teach, Explain, not convinced, just confuse.....
sneha

----- Original Message ----- 
From: Laurel Fan <laurel at sdf.lonestar.org>
To: <courses at linuxchix.org>
Sent: Friday, August 09, 2002 6:49 AM
Subject: Re: [Courses] Re: [C] A clarification on fflush(stderr)


> On Thu, Aug 08, 2002 at 08:40:33PM -0400, Christopher James Lahey wrote:
> > On Thu, 2002-08-08 at 17:10, Laurel Fan wrote:
> > > That's strange.  stderr on my system is unbuffered, unless there's
> > > something wrong with this code:
> > > 
> > > #include <stdio.h>
> > > 
> > > int main()
> > > {
> > >    fprintf(stderr, "stderr is unbuffered");
> > >    sleep(60);
> > > }
> > 
> > Might it be line buffered?  What happens if you put a \n at the end of
> > the string?
> 
> I'm pretty sure it's not line buffered.
> 
> It is unbuffered, which means it printed "stderr is unbuffered" right
> away.  If it was line buffered, it would not print "stderr is
> unbuffered" right away.
> 
> I imagine putting a \n at the end of the string would cause it to
> print a newline.
> 
> -- 
> laurel at sdf.lonestar.org
> http://dreadnought.gorgorg.org
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://linuxchix.org/pipermail/courses/attachments/20020809/2df1fb3c/attachment.xhtml


More information about the Courses mailing list