www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/17/08:33:17

Date: Wed, 17 Nov 1999 15:01:24 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Myron Seto <myron_seto AT hotmail DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Question(newbie): strptime alternative
In-Reply-To: <80tp1j$f56$1@nnrp1.deja.com>
Message-ID: <Pine.SUN.3.91.991117145840.17774A-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Wed, 17 Nov 1999, Myron Seto wrote:

> const long secondsperday = (24 * 60 * 60);
[snip]
> printf("%d\n", (mktime(&second) - mktime(&first)) / secondsperday);

This is non-portable: you are assuming that time_t is in seconds.  While 
this is true in many libraries, it is not a good idea to rely on this.  
Use the difftime function instead.

> struct tm first, second;
> strptime("10/1/1972", "%x", &first)
> strptime("12/10/1999", "%x", &second)
> 
> for example, but djgpp compiler does not have strptime.  Can someone
> please suggest an alternative?

One alternative is to fill the fields of struct tm variables directly, or 
by using sscanf (if you must to begin with a string).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019