I saw the snippet below somewhere online. The following program doesnt print “hello-out”. The reason I feel is because before it is actually flushed to the console from the buffer,
#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
Is my reason correct? If not what is the correct reason?
You should put
\nat the end of the string to have it flushed, or usefflushto force it out.