Thread: How to use Sleep function?

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    47

    How to use Sleep function?

    EDIT *Just worked out how to do this (include windows.h, sleep(tired*1), tired measured in miliseconds)* Feel free to close thread.


    I've been searching around on google on how to use this. I know i have to #include <unistd.h>, and my source code:

    Code:
    #include <unistd.h>
    #include <stdio.h>
    
    int main(void)
    {
        
        printf("I'll be back in 10 seconds...\n\n");
        sleep(10);
        printf("I'm back!");
        getchar();
        
        return(0);
    }
    The output just prints:
    Code:
    I'll be back in 10 seconds...
    
    I'm back!
    With no interval in between.

    Am I using this incorrectly?

    Thanks
    Last edited by Jake.c; 01-17-2009 at 08:20 AM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If you are using Windows, Sleep takes time in milliseconds.
    If you are using Linux, sleep takes time in seconds.
    Also note the case, because C is case sensitive!
    For Windows, Sleep is defined in Windows.h.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM