snprintf() not the only way
Posted Feb 5, 2004 3:35 UTC (Thu) by
Ross (subscriber, #4065)
Parent article:
snprintf() confusion
Another approach is to calculate the maximum length of the resulting
string. This may be difficult if there are strings or variable formats.
If there are strings you can use the precision specifier to limit the
length of those strings. If it is not possible to staticly determine the
maximum length or it is too large to allocate every time you can do
dynamic determination of the length by testing the lengths of the strings
or of the dynamic formats.
(
Log in to post comments)