Unix and gmtime()

Gary Hennigan ghenniga at nmsu.edu
Thu Dec 20 06:46:20 AEST 1990


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 <stdio.h>
#include <time.h>
#include <sys/time.h>

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 at NMSU.Edu, henninsf at maxwel.NMSU.Edu                      +
+  Electrical Engineering; PhD Student, Computational Electromagnetics      +
+  Physical Science Laboratory (ASS)istant systems programmer               +
+---------------------------------------------------------------------------+



More information about the Comp.lang.c mailing list