Xref: utzoo comp.lang.c:17047 comp.unix.wizards:15109 Path: utzoo!attcan!uunet!husc6!bu-cs!bzs From: bzs@bu-cs.BU.EDU (Barry Shein) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: How to predict size of outcome of vsprintf? Message-ID: <28831@bu-cs.BU.EDU> Date: 19 Mar 89 15:46:08 GMT References: <993@etnibsd.UUCP> <9872@smoke.BRL.MIL> Organization: Boston U. Comp. Sci. Lines: 19 In-reply-to: gwyn@smoke.BRL.MIL's message of 19 Mar 89 05:52:35 GMT From: gwyn@smoke.BRL.MIL (Doug Gwyn ) >No. Sometimes you can accurately predict an upper bound on the output >string length; for example if the format is "%d" and the numerical >argument is known to lie between 0 and 5000, the maximum number of >characters for the *sprintf() output will be 5 (including the null >byte at the end). Another way to say that is: print_width = LOGx(N) + 1 where x (the log base) is the base to be printed in, 10 for %d, 16 for %x, 8 for %o etc. And add one for sign (+-) if needed. But of course that doesn't help a lot except with the simplest cases (eg. try "%-5.*g"). -Barry Shein