How to predict size of outcome of vsprintf?
Barry Shein
bzs at bu-cs.BU.EDU
Mon Mar 20 01:46:08 AEST 1989
From: gwyn at 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
More information about the Comp.unix.wizards
mailing list