delay or sleep?

This is a discussion on delay or sleep? within the C Programming forums, part of the General Programming Boards category; i posted a thread some while ago about sleep i wanted to sleep for 0.5 seconds this woldnt work because ...

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

    delay or sleep?

    i posted a thread some while ago about sleep i wanted to sleep for 0.5 seconds this woldnt work because its sleep(int)
    then why dont use delay(500) because it does the same but
    in my last thread about sleep nobody mentioned delay() is this a "bad function" like gets()???

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Sleep does accept an integer. But, Sleep uses miliseconds so you'd actually want to specify 500. Specifiying 500 would pause for half a second.
    The world is waiting. I must leave you now.

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Originally posted by Shadow
    Sleep does accept an integer. But, Sleep uses miliseconds so you'd actually want to specify 500. Specifiying 500 would pause for half a second.
    as said sleep uses an integer i dont know if its on all compilers but try to do sleep(500);
    it wont sleep for half a second it wil sleep for 500 sec.
    thats how it is on my compiler Bc 4.5...
    and oh before i said sleep was ansi but it appears not to be ansi
    so why do i see a lot of people using sleep while its not ansi and delay is???
    Last edited by GanglyLamb; 12-12-2002 at 08:04 AM.

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    UNIX/Linux: sleep(seconds) - unistd.h
    Windows API: Sleep(miliseconds) - windows.h

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    sleep on *NIX is seconds, if you are on *NIX try man usleep

  6. #6
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Originally posted by Monster
    UNIX/Linux: sleep(seconds) - unistd.h
    Windows API: Sleep(miliseconds) - windows.h
    all of this is very cool .......... BUT if i include windows.h the compiler says cannot include windows.h .....

  7. #7
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    If you don't have unistd.h or windows.h then you should get a newer compiler.
    Real respect comes from those that have the knowledge to understand what you've done and the experience to appreciate it. It's the Crack Cocaine of programming.

  8. #8
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Is borland compiler C++ 4.52 not "new" enough .....?

  9. #9
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    i doubt it, Borland's latest compiler is 6, I use the free 5.5 compiler and it has windows.h.
    Real respect comes from those that have the knowledge to understand what you've done and the experience to appreciate it. It's the Crack Cocaine of programming.

  10. #10
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Damn this , i even got this one for "free"+its not a student compiler hmm now i know what the Santa is gonna bring me...

  11. #11
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Just a little question. Is there an easy way to write my own sleep ( ) function that works with milliseconds?

  12. #12
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    You can get a really good completely free upgrade at http://www.borland.com/products/down...cbuilder.html#. It's the one I use and it's great. It's the second one on the list.
    yea, you can write your own sleep, but it's not a good idea. If you really have to, you can do something like this.
    Code:
    #include <stdio.h>
    #include <time.h>
    
    waitie(double seconds){
        clock_t end = clock() + (seconds * CLOCKS_PER_SEC);
    
        while (clock() < end)
            ;
    }
    
    main(){
        int stat = 0;
    
        while (stat < 100){
            printf("Status:%d%%\r", stat++);
            waitie(.2);
        }
    
        printf("Complete...\n");
    }
    Last edited by Pioneer; 12-12-2002 at 11:50 AM.
    Real respect comes from those that have the knowledge to understand what you've done and the experience to appreciate it. It's the Crack Cocaine of programming.

  13. #13
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    No need to wait, there are plenty of truly free compilers available
    Do you mean with truly free that all the functions are available and the apps compiled on that compiler will also work on aonther system then the system where the app is created on?

    And lcc-win32(hate to say this ), but i think thats a really bad compiler(IMO).

    thx for the example Pioneer (although someone said that code was crap ill use it because i need a thing that can sleep for 0.5 sec no matter what)
    Last edited by GanglyLamb; 12-12-2002 at 11:55 AM.

  14. #14
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Didn't we allready go over how no-no this was??

    Originally posted by Pioneer


    You can get a really good completely free upgrade at http://www.borland.com/products/down...cbuilder.html#. It's the one I use and it's great. It's the second one on the list.
    yea, you can write your own sleep, but it's not a good idea. If you really have to, you can do something like this.
    Code:
    #include <stdio.h>
    #include <time.h>
    
    waitie(double seconds){
        clock_t end = clock() + (seconds * CLOCKS_PER_SEC);
    
        while (clock() < end)
            ;
    }
    
    main(){
        int stat = 0;
    
        while (stat < 100){
            printf("Status:%d%%\r", stat++);
            waitie(.2);
        }
    
        printf("Complete...\n");
    }

  15. #15
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Didn't we allready go over how no-no this was??
    yup we did, but if you need a sleep(0.5) and u dont have windows.h "everything" will do. It's like Makavelli said:
    (not sure bout the translation into english)the purpose "holies" the ways.Or something like that.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 08:26 PM
  2. making my program sleep / wait / delay...
    By bobthebullet990 in forum C++ Programming
    Replies: 4
    Last Post: 08-13-2006, 11:14 AM
  3. Create a delay without using Sleep
    By Bag a Bones in forum C++ Programming
    Replies: 12
    Last Post: 01-25-2006, 10:35 PM
  4. sleep() or delay() headers?
    By Gnoober in forum C++ Programming
    Replies: 2
    Last Post: 10-09-2002, 04:25 PM
  5. program delay (sleep)
    By rxg00u in forum C++ Programming
    Replies: 5
    Last Post: 04-16-2002, 01:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21