Mail Archives: djgpp/1997/10/15/07:27:00
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 -