Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!hc!lll-winken!uunet!etnibsd!sean From: sean@etnibsd.UUCP (Sean McElroy) Newsgroups: comp.lang.c Subject: Re: How to predict size of outcome of vsprintf? Summary: Prediction by numerical magnitude alone inaccurate Keywords: vsprintf formatted conversion Message-ID: <996@etnibsd.UUCP> Date: 20 Mar 89 18:30:09 GMT References: <993@etnibsd.UUCP> <9872@smoke.BRL.MIL> Reply-To: sean@etnibsd.UUCP (Sean McElroy) Organization: Eaton Ion Beam Systems Division, Beverly, MA Lines: 24 In article <9872@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >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). If the format specification contains field width specifiers, this will not work (e.g. sprintf ("%10d", 5000); uses 10 chars + 1 for terminator). This implies that the format specifications need to be parsed in a manner similar to *sprintf in order to accurately predict the number of chars in the result. I was looking for something which did nor require me to re-write *sprintf. Also recall that the original problem stated that the types of the input arguments were unknown. This implies that the type must be gleaned from the format specification itself. Although I'm no expert, I presume that this is the mechanism *sprintf uses as well (e.g. %d means take whatever the next input argument is and treat it as an int). -- ____,.,_..,__.,_.,__ Sean Philip McElroy __'..__._,_.__.__.__ Eaton Corp., SED _,___`_.'__.__.__.__ 108 Cherry Hill Dr., Beverly, MA 01922 ___`..'_,___.__.__,_ uunet!etnibsd!sean