[LCP]time

Giri Rajaram girir at yahoo.com
Sat Jan 19 07:06:12 UTC 2002


You haven't initialized the 'time_t now' variable. 
'localtime' takes in a 'const time_t *' as its
argument, so don't expect it to set the value of
'now'. 'now' can be initialized by:
   now = time(NULL);
and that should solve the problem.

-Giri

--- Joachim Bauernberger <bj at gmx.net> wrote:
> Hi,
> I am having a little problem with time. For some
> reason the code below will 
> have the following output:
> 
> [bjdev: C]$ ./time
> 12 41 10 23 11 35 1
> Mon Dec 23 10:41:12 1935
> 
> The actual time however is:
> [bjdev: C]$ date
> Fre Jan 18 20:35:29 CET 2002
> 
> 
> Can somebody be so kind and tell me what I am doing
> wrong (maybe it's time 
> for me to get some sleep .... :))
> 
> 
> Here is the code:
> 
> #include <time.h>
> #include <stdio.h>
> 
> int main( int argc, char **argv) {
> 
>     time_t          now;
>     struct tm       *tt;
>     char *c;
> 
>     tt = localtime(&now);
>     //c = ctime(&now);
> 
>     fprintf(stdout,"%d %d %d %d %d %d
> %d\n",tt->tm_sec, tt->tm_min, 
> tt->tm_hour, tt->tm_mday, tt->tm_mon, tt->tm_year,
> tt->tm_wday);
>     //fprintf(stdout,"\n%s\n",c);
>     c = asctime(tt);
>     fprintf(stdout,"%s\n",c);
> 
> return 0;
> }
> 
> -- 
> You can get my public pgp key here:
> http://www.mxscan.com/pgp/joachim.asc
> PGP fingerprint:
> 25 96 E0 25 48 D9 8E 10  3C C0 48 E7 AF 5A E2 C6  A3
> 15 05 E6
> 
> _______________________________________________
> This is the Linux C Programming List
> : 
> http://lists.linux.org.au/listinfo/linuxcprogramming
List


__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/



More information about the linuxCprogramming mailing list