Xref: utzoo comp.lang.c:36659 comp.unix.programmer:1191 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.lang.c,comp.unix.programmer Subject: Re: help to new C programmer with time.h Message-ID: <1991Mar1.071615.18895@athena.mit.edu> Date: 1 Mar 91 07:16:15 GMT References: <5284@vela.acs.oakland.edu> Sender: news@athena.mit.edu (News system) Followup-To: comp.unix.programmer Organization: Massachusetts Institute of Technology Lines: 66 In article <5284@vela.acs.oakland.edu>, swood@vela.acs.oakland.edu ( EVENSONG) writes: |> #include "stdio.h" |> #include "time.h" |> |> main() |> { |> struct tm tt; |> time_t lt; |> int d, m; |> |> time(<); |> d = tt.tm_mday; |> m = tt.tm_mon; |> |> printf("Day %d Month %d\n", d, m); |> } First of all, this is an OS-specific question, not a C question, because the C language does not define how to get the time; any functions for getting the time in C are OS-specific library functions, not standard C functions. Since the functions and structures you are using appear to me to be Unix library structures and functions, I have cross-posted my response to comp.unix.programmer and directed followups there. Second, how exactly do you expect tt to be filled in? Do you expect a call to the time library function which doesn't even pass in tt to magically fill it in somehow? I think what you want to do is this: #include #include #include main() { struct tm *tt; time_t lt; int d, m; time(<); tt = localtime(<); /* Remember that the return value of localtime points to static data which will be destroyed on the next call to it. */ d = tt->tm_mday; /* this is the day of the month */ m = tt->tm_mon; /* this is the month */ printf("Day %d Month %d\n", d, m); } Of course, something here may be wrong, if the OS you're working on is significantly different from what I'm using, which is why I say that this is an OS-specific question. By the way, it usually helps, when asking about something that you cannot get to work, to explain *how* it's not working. Does the program not compile at all? Does it compile but produce bad output? If so, what output does it produce? The more specific you are, the more likely it is that other people will be able to help you. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710