Thread: Do "Sleep()" exists in C Language?

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    1

    Do "Sleep()" exists in C Language?

    Hi,
    Perhaps I am asking a silly question, but I really don't know about it. Can anyone tell me the function for "sleep" kind of functionality in C language for Unix. I don't think any function with the name of sleep() exits in Unix's C language. or perhaps I am not known with the header file required for this. Can anyone guide me about the correct function to halt the program execution for a specified time? Do tell me the header file required for the function as well.

    Regards,

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I don't think there is (correct me if I'm wrong). The usual hack is:


    Code:
    #include <time.h>
    
    void wait(unsigned timeout)
    {
     timeout += clock(); 
     while(clock() < timeout)
      continue;
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    There is no sleep function in standard C, but your OS may provide such a function. What OS are you using? In case of a Unix-like OS there is function sleep(), it's part of the POSIX standard, you need to include unistd.h for that.

    http://www.opengroup.org/onlinepubs/.../unistd.h.html

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. language pack
    By VOX in forum Tech Board
    Replies: 3
    Last Post: 07-13-2005, 05:05 PM
  2. What language did they make Java in?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 07-03-2005, 04:18 PM
  3. Which Language? need help ASAP
    By jcw122 in forum Tech Board
    Replies: 7
    Last Post: 03-07-2005, 04:16 PM
  4. Strange loop
    By D@rk_force in forum C++ Programming
    Replies: 22
    Last Post: 12-18-2004, 02:40 PM
  5. Your own programming language!
    By cogeek in forum Tech Board
    Replies: 9
    Last Post: 08-26-2004, 08:04 AM