Mail Archives: djgpp/1997/10/14/22:24:39

Date: Tue, 14 Oct 1997 19:23:32 -0700 (PDT)
Message-Id: <>
Mime-Version: 1.0
To: Peter Palotas <blizzar AT hem1 DOT passagen DOT se>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: sprintf() string length?

At 09:44  10/14/1997 -0400, 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!
I don't think so :(  GNU's libc has functions called (IIRC) `nsprintf',
which takes a length argument and will write only that many characters, and
`asprintf' which automatically malloc()s/realloc()s a buffer you give it.
But DJGPP doesn't have it, and GNU's printf()/etc. code is very complicated.
Also it's GPL, I think. All I can think of is to malloc a huge buffer, and
then use realloc to shrink it based on the return value of sprintf().

Nate Eldredge
eldredge AT ap DOT net

- Raw text -

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