Unix and gmtime()
John Stanley
stanley at phoenix.com
Thu Dec 20 11:21:41 AEST 1990
ghenniga at nmsu.edu (Gary Hennigan) writes:
> 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.
Because you are passing garbage to gmtime().
> ----------------------------------------------------------------------
> #include <stdio.h>
> #include <time.h>
> #include <sys/time.h>
>
> main()
> {
> struct tm *clock;
> int i1=1, i2;
> char *tod;
time_t mytime;
time(&mytime);
clock = gmtime( &mytime );
> tod = asctime( clock );
>
> printf("%s\n", tod );
>
> return 1;
> }
> ----------------------------------------------------------------------
I don't have access to the UNIX man pages for gmtime, but I can't
believe they don't show a required parameter. Wouldn't it be nice if
all compilers would use prototypes. My TC 2.0 refused to compile the
original code, telling me that gmtime was missing required parameters.
More information about the Comp.lang.c
mailing list