Pejman Moghadam / C-programming

C - stdout buffer

Public domain


Checking buffer size

#include <stdio.h>
/* This program show's first output after 377 seconds
 * so it seems there is 1024 byte buffer for stdout 
 */
main()
{
        int i;
        for(i=0;;i++)
        {
                printf ("%d",i);
                sleep (1);
        } 
        return 0;
}

Flushing buffer

#include <stdio.h>
/* This program show's output every second */
main()
{
        int i;
        for(i=0;;i++)
        {
                printf ("%d",i);
                fflush (stdout); 
                sleep (1);
        } 
        return 0;
}

BY: Pejman Moghadam
TAG: c, stdout_
DATE: 2011-06-01 13:27:40


Pejman Moghadam / C-programming [ TXT ]