if so, does it have to do with time.h?
if so, does it have to do with time.h?
First, If you're talking about microsoft C, you can get the source code from the site in the source code section. If not, you can find out by looking in the file for time.h They will have all the function declarations in there. It'll probably be called timer() or something really obvious. Hope you find it!
What operating system are you using, and what compiler?
I'm using codewarrior. And it's on win 2000. But I'll look at the source code.
One option is to use GetTickCount(), part of the win32 api. Include <windows.h> to use.
I think time.h also has some functions for timing, but may not be as accurate. For more accuracy than milliseconds, use the search function. There was a good post about this a couple of months ago on the c programming board.Code:#include <iostream> #include <windows.h> using namespace std; int main(void) { DWORD start, end; cout << "Hello." << endl; start = GetTickCount(); Sleep(1000); //Sleep 1 second end = GetTickCount(); cout << "start:" << start << " end:" << end << endl; cout << "millisec elapsed:" << end-start << endl; cout << "Good bye." << endl; return 0; }
Last edited by swoopy; 12-14-2001 at 01:29 AM.
Thanx!!! That helps out alot. I was looking to find milliseconds. However, do I have to use namespace? I don't really enjoy using that.
>However, do I have to use namespace?
No, in fact I'm not real fond of it myself. Just:
#include <iostream.h>
#include <windows.h>
and leave out the namespace.
i've written a simple little function that takes a "Timeout" for x number of seconds ( a double variable ):
include <time>
void Timeout(double length)
{
int starttime = time(0);
while(time(0) - starttime < length)
{
}
}
so Timeout(.5) would wait for a half second.