c - what does sleep do by default? does it goes for sleep for actual timing -


this question has answer here:

hi following simple code while 1, when execute , first should print first line in printf , sleep 1 sec , print second line , should keep on doing here don't in terminal , after few seconds printed , goes sleep . happening not understanding .

int main(void) {   while(1)  {     printf("hello before sleep");     sleep(1);     printf("hello after sleep");   } } 

but in same code above if use \n after every line in printf works fine expected . why ?

printf , more output functions buffered. if want see expected behavior should flush output before going sleep.

fflush(stdout); sleep(1); 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -