[C] Timed Cycle

Results 1 to 6 of 6
  1. #1
    Sorcerer Supreme raima is offline
    Member +Rank
    Aug 2005 Join Date
    EuropeLocation
    336Posts

    [C] Timed Cycle

    hi guys

    i want to ask a question... does anyone know a good way to make timed cycle? because using for (i=0;i<20000000000000000000000000000;i++) works really differently on different pc...


  2. #2
    Grand Master Daevius is offline
    Grand MasterRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    Re: [C] Timed Cycle

    Try and look for sleep functions, these delay the execution of the program instead of looping (and thus using CPU!). Always use sleep and no loops for this.

    windows.h has a Sleep() function, google it.

  3. #3
    Sorcerer Supreme raima is offline
    Member +Rank
    Aug 2005 Join Date
    EuropeLocation
    336Posts

    Re: [C] Timed Cycle

    okay, so i have found sleep () function for linux in unistd.h but the problem is that it works with Seconds, not miliseconds... any advices?

  4. #4
    Grand Master Daevius is offline
    Grand MasterRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    Re: [C] Timed Cycle

    microsleep() ? Perhaps working with decimals works...10 ms is the lowest you can get though (depending on your CPU), even if you say it should be 1 ms.

  5. #5
    Sorcerer Supreme raima is offline
    Member +Rank
    Aug 2005 Join Date
    EuropeLocation
    336Posts

    Re: [C] Timed Cycle

    ty 4 help but i've found a better thing
    usleep



    WTB lib and command to change color -.- not whole screen text but some specific output and etc

  6. #6
    Sorcerer Supreme Sprayz is offline
    Member +Rank
    Nov 2006 Join Date
    Alive : Spain | Dead : Beer Vulcano HeavenLocation
    279Posts

    Re: [C] Timed Cycle

    Quote Originally Posted by Daevius View Post
    Try and look for sleep functions, these delay the execution of the program instead of looping (and thus using CPU!). Always use sleep and no loops for this.

    windows.h has a Sleep() function, google it.
    Also take into account that if you use the sleep fuction on a singel threaded program it will HANG ON for the said number of seconds.



Advertisement