0

My code:

#include <stdio.h>
#include <unistd.h>

int main(){
    printf("I sleep\n");
    sleep(3);
    printf("\033[H\033[J");
    return 0;
}

if I don't write "\n" in the printf-function, "I sleep" wil not be displayed, until sleep(3) is done.

Can someone explain? Thanks!

1 Answers1

1

The standard output stream, when not outputting to a file or device, is line-buffered by default on most UNIX-like systems.

That mean that text sent there typically won't actually be printed until a newline character is encountered.

dbush
  • 205,898
  • 23
  • 218
  • 273