I have trouble finding out hot to get my program use the pc clock to get the time. Is it possible. How do I do it?
I have trouble finding out hot to get my program use the pc clock to get the time. Is it possible. How do I do it?
it is possible to read the system time, i cant remember the time at the moment but you use a struct called time. check the headers time.h and dos.h - soryy i cant be more specific at the moment
Monday - what a way to spend a seventh of your life
include time.h
time(NULL) i think does it.
For Visual Basic
you can access time by using
time
or Now
For c++
Use the functions in time.h and (possibly dos.h)
im not to sure what they are but I think they are time();
and another one.
time() returns the system time and stores it as a pointer to type time_t passed as the argument, or as variable of type time_t. The prototype is below and is found in time.h or ctime (depending on the version of your compiler)
time_t time(time_t*);
time_t is typedefed as type long and represents the difference in seconds from a given point in time (which point in time is compiler version specific). Since this information is useful in some circumstances and not in others, there are several other functions that will convert the time_t* into a more useful version. One is ctime(). Here's the prototype:
char * ctime(time_t*);
The string returned is 28 or so char long and has a format similar to :
Monday Dec 31, 1999 21:43:56
I forget the exact format.
localtime() is another useful function. It has the prototype:
tm localtime(time_t*);
tm is a struct defined in time.h something like this:
struct tm
{
int tm_month;
int tm_day;
int tm_year;
int tm_hour;
int tm_min;
int tm_sec;
int tm_wkday;
};
that you can then manipulate at your discretion.
As previously discussed you should look all these functions and structs up in your compilers help section for all the specific details. Here's some off the cuff, non-compiled examples of how you might use these functions/stucts/whatever:
#include <time.h>
#include <string.h>
//whatever else
time_t now;
time_t * pNow;
char szNow[30];
now = time(NULL);
time(pNow);
pNow = &now;
tm tmNow = localtime(pNow);
cout << tmNow.hour << ":" << tmNow.min << ":" << tmNow.sec << endl;
strcpy(szNow, ctime(pNow));
cout << szNow;