Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!mtuxo!mtune!akguc!akgua!gatech!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP Newsgroups: net.lang.c Subject: Re: time(2 or 3) Message-ID: <2021@umcp-cs.UUCP> Date: Sun, 15-Jun-86 15:05:04 EDT Article-I.D.: umcp-cs.2021 Posted: Sun Jun 15 15:05:04 1986 Date-Received: Tue, 17-Jun-86 11:06:42 EDT References: <337@lll-lcc.UUcp> <798@isis.UUCP> Reply-To: chris@maryland.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 40 In article <798@isis.UUCP> jay@isis.UUCP (Jay Batson) writes: [approximately] >#include > >some_fcn(params) >sometype params; >{ > long somevar1; > struct tm *somevar2, *localtime(); > > /* ok, first get ahold of the number of seconds since Jan 1, 1970 */ > somevar1 = time(0); This code is wrong! It is missing two things, both of which are non-fatal on Vaxen and Suns and probably 70% of the machines out there. Specifically, time() is a function returning long, taking a pointer to long; or a function returning time_t, taking a pointer to time_t (just which depends on your Unix variant). Some systems do not define time() in . Change to: struct tm *somevar2, *localtime(); long time(); somevar1 = time((long *) 0); or add `#include ' and use `time_t' in place of `long' above. > somevar2 = localtime(&somevar1); /* note &somevar1 passes a pointer */ > > printf("The current time is: %2d:%2d:%2d (on a 24 hour clock)\n", > somevar2->tm_hour, somevar2->tm_min, somevar2->tm_sec); >} /* end some_fcn */ Just for prettiness, the minute and second conversion formats should be `%02d'. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu