The sleep() function doesn't seem to be respecting line by line compilation in c whenever I run something like this:
#include <stdio.h>
#include <unistd.h>
int main(){
int i=0;
while (i!=9){
printf("sleep for 1 second");
sleep(1);
i++;
}
return 0;
}
The output ends up being "sleep for 1 second" printed out 10 times after waiting for 10 seconds, instead of the desired one of printing out "sleep for 1 second" every second for 10 seconds. Anyone know why this is and how to fix it?