raam wrote:
Hello all,
I am using Turbo c 2.1.
I have reqritten the timer interrupt in PC as per my requirement.When
I use gettime() and getdate()
in my program leter I am not getting current time and date.How to get
the Time and Date directly from the CMOS.
Thanks in advance.
In the C programming language as it is defined, there is no such thing
as "CMOS". Nor are there such things as gettime() or getdate().
You get the current time and date with functions declared in <time.h>.
In particular, you can get the current calendar time with (surprise!)
the function time(), which returns a variable of type time_t. If all
you want is a string representing the current time and date, you can use
ctime() with the value from time() which returns a pointer to a string.
Here is an example:
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t t;
struct tm tstruct;
t = time(0);
tstruct = *localtime(&t);
printf("The time from ctime is %s", ctime(&t));
printf("The time from asctime is %s", asctime(&tstruct));
tstruct.tm_min += 6;
t = mktime(&tstruct);
printf("In 6 minutes,\n");
printf("The time from ctime will be %s", ctime(&t));
printf("The time from asctime will be %s", asctime(&tstruct));
return 0;
}
[output]
The time from ctime is Thu May 31 04:52:06 2007
The time from asctime is Thu May 31 04:52:06 2007
In 6 minutes,
The time from ctime will be Thu May 31 04:58:06 2007
The time from asctime will be Thu May 31 04:58:06 2007
If you insist on using implementation-specific (and particular
hardware-specific) things like timer interrupts, CMOS, gettime(), and
getdate(), then you are not writing code that can be used in any other
environment, In fact, many of us will not be able to even compile that
code. Such code is _off-topic_ in <news:comp.lang.c>. You need to
check your documentation and, if you have problems, check a newsgroup or
mailing list for your 20-year-old compiler and its non-standard
functionality, if you can find it.