Xref: utzoo comp.lang.c:17040 comp.unix.wizards:15106 Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!tut.cis.ohio-state.edu!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: How to predict size of outcome of vsprintf? Keywords: vsprintf formatted conversion Message-ID: <9872@smoke.BRL.MIL> Date: 19 Mar 89 05:52:35 GMT References: <993@etnibsd.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 17 In article <993@etnibsd.UUCP> sean@etnibsd.UUCP (Sean McElroy) writes: >O.K. Unix/C gurus, since vsprintf requires the user to ensure that there >is enough space in the output string, how does one predict the size of >the output string? Is there a routine which returns the predicted >length of the output string (effectively preforming the printf conversions) >without actually producing the output string? 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). >Any suggestions welcome. Don't use *sprintf() when you can't be sure that the output length will be small enough. Seriously.