Problem with sleep function in C
Problem with sleep function in C
If you are getting some problem during the execution of the program then you need to check the whole program for any syntactical error.
You specified that the error is generated from the Header file.If the function is not identified by any header file then you need to use the TIME.H header file in the header definition section of the program.
#include <time.h>
and check also you are calling the procedure in different way or the variables which is being used by the program is exist or not.
Example of sleep function in C
Example of sleep function
The sleep function can be structured with a program.As you suggested above from the members and experts,It stops the execution of the program for a specified time interval.
Here,a code is shown which stops the execution of the program for 1 second -
Code:
#include <time.h>
#include <stdio.h>
#include <conio.h>
int main()
{
printf("This is Msg_1 \n");
sleep(1000); //1000 microsecond= 1 second will sleep...
printf("This is Msg_2 after 1 second.......");
getch();
return 0;
}
SLEEP function behavior on different platform
There are some places where we can use this function and they have same functionality but have different syntax and arguments.
The SLEEP function is being used on windows and POSIX compliant systems but the declaration on both places is different from each other.
Declaration on POSIX compliant systems
sleep(time_in_second)
Declaration on windows system
Sleep(time_in_milisecond)
The difference of the S word in both declaration are also separate.
SLEEP declaration on POSIX
SLEEP declaration on POSIX
The declaration of sleep function on POSIX is something different from the windows compliant.The sleep command rejects or stops the execution for time seconds.
(sleep 105; command)&
or if you need to run a command every so often then you can do it as follows-
Code:
while true
do
command
sleep 37
done