Monday, 26 August 2013

printf on linux vs windows

printf on linux vs windows

here is some C code :
int i;
printf("This text is printed\nThis text is not until the for loop end.");
for (i = 5; i > 0; i--)
{
printf("%d", i);
sleep(1);
}
Why the rest of the text after the '\n' is not printed before the for loop
start? Even the printf inside the for loop is only printed after the loop
end. If I put a '\n' at the end of the text, it print, but I do not want a
new line.
This only happen on Linux and not on Windows (just changed sleep(1) to
Sleep(1000) and added windows.h).
Thanks

No comments:

Post a Comment