Thread: sleep (in a loop)

  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110

    sleep (in a loop)

    i use sleep(0.5) in a loop now my problem is when i run it the app doesnt wait for 0.5 seconds but it goes way faster does any one knows how this could happen and how i can prevent it from happening ....because i like sleep(alot) and its kinda "dumb" that it wont work

    if it would be helpfull im on win-98 SE
    im using BC 4.5 for this console app.

  2. #2
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    sleep takes an int argument, when you pass it .5 it actually gets 0 and doesn't sleep at all.

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    so ur saying even if i say
    Code:
    float t=0.5;
    sleep(t);
    it wont even work ......
    is there anyway how i can make it work with 0.5 so with a float ??

  4. #4
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    When a float is converted to an int, everything past the decimal is cut off. Since everything before the decimal is 0 and everything after is cut off, you have 0. sleep from dos.h is obsolete anyway, use Sleep(500) and include windows.h, that'll do what you want.

  5. #5
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    BC 4.5 says=>
    #include <dos.h>
    void sleep(unsigned seconds);
    Suspends execution for an interval (seconds). With a call to sleep, the current program is suspended from execution for the number of seconds specified by the argument seconds. The interval is accurate only to the nearest hundredth of a second or to the accuracy of the operating system clock, whichever is less accurate.

    0.01 should be possible as an argument i presume or mayb im just a dumb kid ...(that doenst know a word english)

  6. #6
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    That's the accuracy of sleep, it means if you pass it 1 it may not sleep for exactly 1 second. That has nothing to do with what argument you can pass to it.

  7. #7
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    0.01 should be possible as an argument i presume or mayb im just a dumb kid .
    finally its proven am soo dumb /doctors couldnt find the answer to my problems in highschool but now i know/
    and errr thx anyway

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 07:19 AM
  4. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM