Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!dimacs.rutgers.edu!seismo!uunet!ceco!garry From: garry@ceco.ceco.com (Garry Garrett) Newsgroups: comp.lang.c Subject: Re: help to new C programmer with time.h Message-ID: <425@ceco.ceco.com> Date: 2 Mar 91 00:28:03 GMT References: <5284@vela.acs.oakland.edu> Organization: Commonwealth Edison Co., Chicago, IL Lines: 40 In article <5284@vela.acs.oakland.edu>, swood@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.