Date: Wed, 15 Oct 1997 13:26:54 +0200 (IST) From: Eli Zaretskii To: Peter Palotas cc: djgpp AT delorie DOT com Subject: Re: sprintf() string length? In-Reply-To: <3.0.16.19971014214406.2c573b3e@hem1.passagen.se> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk 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).