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.
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.
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.
what header are they in? or what library do I need to get?
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.
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
For Windows, include Windows.h and check MSDN for Sleep(). For *nix..... I don't know. Check the man pages for sleep().
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?