delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/15/07:27:00

Date: Wed, 15 Oct 1997 13:26:54 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Peter Palotas <blizzar AT hem1 DOT passagen DOT se>
cc: djgpp AT delorie DOT com
Subject: Re: sprintf() string length?
In-Reply-To: <3.0.16.19971014214406.2c573b3e@hem1.passagen.se>
Message-ID: <Pine.SUN.3.91.971015132633.17868O-100000@is>
MIME-Version: 1.0

On Tue, 14 Oct 1997, Peter Palotas wrote:

> Is there a way to find out the length of the string that sprintf() will
> generate, without writing it anywhere? i.e. if I want to dynamically
> allocate the storage space for the string this would be very good (read
> essential) to know!

You could make a crude estimation by walking through the format string
and assuming each % conversion specifier which doesn't have an
explicit character count produces the maximum possible length.  A more
accurate way would be to know the default length for each conversion
letter (%s will need to get the length of the argument).

- Raw text -


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