Error Compiling C Code with Time and Date Functions.

Carl Flippin carlf at photocarl.org
Wed Dec 10 01:06:12 UTC 2008


On Tue, Dec 09, 2008 at 03:32:35PM -0600, Martin McCormick wrote:
> 	I portedd some code I had written in FreeBSD unix over to
> a new ubuntu-server system only to discover that none of the
> time and date functions compile in Linux but do so under
> FreeBSD. When referencing members of the structure timeptr such as
> 
> (timeptr->tm_year - 100), (timeptr->tm_mon) + 1,     timeptr->tm_mday);
> 
> 	compilation finds an error every time. The following
> fragment will produce the error:
> 
>     struct tm *timeptr;
>     time_t elapsed_seconds; /*since midnight 1/1/70*/
>     time(&elapsed_seconds);
>     timeptr = localtime(&elapsed_seconds); /*fill structure*/
> sprintf(newalarm,"alarms%02d%02d%02d", (timeptr->tm_year - 100), (timeptr->tm_mon) + 1,     timeptr->tm_mday);

*snip*

> #include <sys/time.h>

Your problem seems to be here. On my machine at lease, time.h is not
in /usr/include/sys. It's in /usr/include. The struct you are making a
pointer to above is not defined in sys/time.h. You need:

#include <time.h>

I do see the struct defined there. It is a part of libc6-dev.

-- 
Carl Flippin         | An idealist is one who, on noticing that a
carlf at photocarl.org  | rose smells better than a cabbage, concludes
http://photocarl.org | that it will also make a better soup.
_____________________|      -- H. L. Mencken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20081209/d919081b/attachment.pgp>


More information about the ubuntu-users mailing list