Xref: utzoo comp.unix.programmer:729 comp.lang.c:34856 Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!news.cs.indiana.edu!ariel.unm.edu!nmsu!opus!ghenniga From: ghenniga@nmsu.edu (Gary Hennigan) Newsgroups: comp.unix.programmer,comp.lang.c Subject: Unix and gmtime() Message-ID: Date: 19 Dec 90 19:46:20 GMT Sender: news@NMSU.Edu Followup-To: comp.unix.programmer Distribution: comp Organization: NMSU Computer Science Lines: 42 I'm fairly new to C programming and have run into a fairly difficult problem, at least it seems difficult to me! I'm trying to get the current time using the gmtime() and/or localtime() functions but what I get is garbage. I know that my "tm" structure is being initialized but it's being initialized to garbage, eg., I get a time of Dec. 31, 2002 or some such upon returning from the asctime() function. If anyone's ever used either of these functions on a UNIX machine, or if you have any ideas as to what I'm doing wrong I would greatly appreciate the assistance. Here's the short piece of code I'm working on: ---------------------------------------------------------------------- #include #include #include main() { struct tm *clock; int i1=1, i2; char *tod; clock = gmtime(); tod = asctime( clock ); printf("%s\n", tod ); return 1; } ---------------------------------------------------------------------- Again the structure "clock" is being initialized and asctime is converting what it gets properly, it's just that what it gets is incorrect. Thanks in advance and please email if possible, -- Gary Hennigan +---------------------------------------------------------------------------+ + e-mail: ghenniga@NMSU.Edu, henninsf@maxwel.NMSU.Edu + + Electrical Engineering; PhD Student, Computational Electromagnetics + + Physical Science Laboratory (ASS)istant systems programmer + +---------------------------------------------------------------------------+