Mail Archives: djgpp/1997/10/14/22:24:39
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 -