Thread: Sleep

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    319
    Rep Power
    8

    Sleep


    Is there any function like sleep or wait in C ?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Yes. sleep() under most *Nixes and Sleep() in Windows. Note the case of the function names. By the way, sleep() takes its parameter in seconds and Sleep() in microseconds.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    If you're using the MinGW port of gcc, which is what Dev-C++ uses, then the function is sleep(). Even though the LibC help file states that the parameter is in seconds, it's actually in milliseconds.

    It's best to write a short test program to verify what your compiler's version of sleep does.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    18
    Sleep() is in milliseconds, not microseconds.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    Novi Sad
    Posts
    20
    Rep Power
    0
    If using gcc then also there is a function called
    Code:
    usleep(microSeconds);
  10. #6
  11. Advanced Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Malaysia
    Posts
    452
    Rep Power
    41
    if your doing windows programming , you can use WaitForSingleObject to wait . The parameter is a handle of a wait object. You can create a semaphore or event as the wait object.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music."
    - Kristin Wilson, Nintendo, Inc., 1989.

IMN logo majestic logo threadwatch logo seochat tools logo