Link to home
Start Free TrialLog in
Avatar of hongjun
hongjunFlag for Singapore

asked on

Sleep Function

I have this piece of code.

printf("Exiting .");
sleep(1);
printf(" .");
sleep(1);
printf(" .");
sleep(1);
printf(" .");
sleep(1);
printf(" .");


I want to produce some sort of animation but then it does not seem to work as expected in unix/linux. The code works fine on windows. How to make that work in unix/linux?


hongjun
Avatar of sunnycoder
sunnycoder
Flag of India image

on windows sleep is in milliseconds and on linux it is in seconds ...
use usleep or nanosleep to achieve what you want
Avatar of hongjun

ASKER

I am aware of the differences b/w windows and linux and that's why I do a sleep(1). I am trying to do this animation
Exiting .
ONE SECOND LATER
Exiting . .
ONE SECOND LATER
Exiting . . .
ONE SECOND LATER
....
.....


hongjun
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the above code will flush the buffers
to turn off buffering, refer to this
http://oldlook.experts-exchange.com/questions/20675234/io-redirection-of-printf.html