Thread: Timer?

  1. #1
    Registered User
    Join Date
    Jul 2007
    Location
    Texas
    Posts
    103

    Timer?

    Is there a way to make a timer in C, like a real time timer.. such as it starts counting down from 30 and when it is equal to 0 something happens.... if anyone knows how to do that or part of it.. please help.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You could use sleep() on *nix systems or Sleep() on Windows. Those two functions take different arguments, so read the documentation before using them. Combined with threads, you can build your own timers. Otherwise, libraries and maybe even *nix and Windows specific options may be available.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Location
    Texas
    Posts
    103
    what header are they in? or what library do I need to get?

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Windows has better ways of handling it's own time, but the header file, time.h has some functions that may still be good enough for your use.

    difftime(), for instance, if accuracy to roughly a second is enough. Don't even think for a milli-second that anything you get from most OS's is going to be real time.

    Other functions in time.h give finer accuracy, but still far from real time. To get real time accuracy, you need real-time hardware and a way to send/receive messages from it, also in real time.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Location
    Texas
    Posts
    103
    well what I meant by real time is just like an actual second... not just how long it takes to count.. i don't care if it is 4:00.30 or 6:00.30...I just need to know like that is it a real second or a real minute

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    For Windows, include Windows.h and check MSDN for Sleep(). For *nix..... I don't know. Check the man pages for sleep().

  7. #7
    Registered User
    Join Date
    Jul 2007
    Location
    Texas
    Posts
    103
    well, that did work, but is there a way to make it like if you ahve to OS's on ur computer, like a live countdown.. instead of having to either have no countdown (like with sleep())... or you have to print a new line.. but I just want a number that refreshes itself in the same line... is that possible?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM
  4. Timer again.
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 05-04-2005, 10:19 PM