help to new C programmer with time.h
Garry Garrett
garry at ceco.ceco.com
Sat Mar 2 11:28:03 AEST 1991
In article <5284 at vela.acs.oakland.edu>, swood at vela.acs.oakland.edu ( EVENSONG) writes:
>
> I am delving into learning C programming this week, and I was in the process
> of converting one of my old basic programs over to C, and got to noting that
> instead of input day and month directly, I could take it directly off of the
> system clock. But, I can not seem to get it to work. Here is one of
> multiple combinations that I tried:
>
> ---------------------cut here------------------
> #include "stdio.h"
> #include "time.h"
>
> main()
> {
> struct tm tt;
struct tm *tmptr;
> time_t lt;
> int d, m;
>
> time(<);
tmptr = localtime(<);
d = tmptr->tm_mday;
m = tmptr->tm_mon;
/*
> d = tt.tm_mday;
> m = tt.tm_mon;
*/
>
> printf("Day %d Month %d\n", d, m);
> }
> ----------------------------cut here-------------------
>
calling the function time merely puts the elapsed number of seconds
since jan 1, 1970 at 00:00:00 into "lt" It does nothing to "tt". If you
want to get a structure tm filled with the current time, then you must use
localtime() to convert this SEC70 representation of time into a struct tm
representation of time. localtime returns a pointer to a struct tm, however,
rather than copying that information into tt, we might as well go ahead and use
it in this example.
More information about the Comp.lang.c
mailing list