help to new C programmer with time.h

Paul Falstad pfalstad at phoenix.Princeton.EDU
Fri Mar 1 18:25:14 AEST 1991


swood at vela.acs.oakland.edu ( EVENSONG) wrote:
>main()
>{
>  struct tm tt;
>  time_t lt;
>  int d, m;
>
>  time(&lt);
>  d = tt.tm_mday;
>  m = tt.tm_mon;
>
>  printf("Day %d Month %d\n", d, m);
>}

Well, obviously the call to time isn't doing a thing to struct tm tt.
You need to explicitly set it.

   struct tm tt;
   time_t lt;

   time(&lt);
   tt = *localtime(&lt);
   d = ...

Or (better)

   struct tm *tt;
   time_t lt;

   time(&lt);
   tt = localtime(&lt);
   d = tt->tm_mday;
   m = tt->tm_mon;

--
Paul Falstad, pfalstad at phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
"So how DO you delete a file called - ?"  For viewers at home, the answer
is coming up on your screen.  For those of you who wish to play it the hard
way, stand upside down with your head in a bucket of piranha fish.



More information about the Comp.lang.c mailing list