Date: Tue, 14 Oct 1997 19:23:32 -0700 (PDT) Message-Id: <199710150223.TAA04268@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: Peter Palotas , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: sprintf() string length? Precedence: bulk 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