Results 1 to 6 of 6

Thread: sleep() function in C

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    sleep() function in C

    I have created a program which prints the string from the array one character at a time.I think to use a sleep function within the for loop. But occurs the error regarding the header file.I need to know the actual functionality of the sleep function and how it would be constructed in the program.

    thanks.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,010

    sleep() function in C

    sleep() function in C

    The sleep is one of the most useful function in C and also used in C++.It provides the delay of execution for a specified time interval depends on the allocated time.The function takes the following form and stored in the time.h header file.

    Sleep(Duration);

    Where the duration describes the time (sleep call in milliseconds) till the execution would be stopped or delayed.

  3. #3
    Join Date
    May 2008
    Posts
    2,302

    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.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,394

    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;
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,393

    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.

  6. #6
    Join Date
    Feb 2008
    Posts
    1,856

    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

Similar Threads

  1. Replies: 3
    Last Post: 27-01-2012, 10:43 AM
  2. Sleep function for Logitech Harmony 525
    By Devabrata in forum Hardware Peripherals
    Replies: 6
    Last Post: 10-06-2010, 06:39 AM
  3. How to write pause, sleep, wait function
    By VinFanatic in forum Software Development
    Replies: 3
    Last Post: 07-07-2009, 03:36 PM
  4. JavaScript Sleep Function
    By DARIELLE in forum Software Development
    Replies: 3
    Last Post: 29-06-2009, 09:30 AM
  5. How to Interrupt Sleep Function in Python
    By Xena in forum Software Development
    Replies: 3
    Last Post: 13-04-2009, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •