Path: utzoo!attcan!uunet!husc6!uwvax!umn-d-ub!umn-cs!attila!papowell From: papowell@attila.uucp (Patrick Powell) Newsgroups: comp.unix.questions Subject: Re: Guessing buffer size needed for sprintf beforehand Message-ID: <5394@umn-cs.cs.umn.edu> Date: 14 May 88 15:34:44 GMT References: <136@insyte.uucp> <7768@ncoast.UUCP> Sender: news@umn-cs.cs.umn.edu Reply-To: papowell@attila.UUCP (Patrick Powell) Organization: University of Minnesota, Minneapolis Lines: 33 Posted: Sat May 14 10:34:44 1988 In article <7768@ncoast.UUCP> allbery@ncoast.UUCP (Brandon Allbery) writes: >As quoted from <136@insyte.uucp> by jad@insyte.uucp (Jill Diewald): >+--------------- >| One solution is to fprintf into a file opened to be /dev/null. >| This requires two calls to the c print fuctions, one to get the >| size and the second to actually print. Since the first call >| goes to dev/null it should be faster since it doesn't really >| write anything? (Is this true? For all UNIXs?). This won't >| work for VMS though. >+--------------- (Brandon talks about v?printf). >++Brandon >-- > Brandon S. Allbery, moderator of comp.sources.misc > {well!hoptoad,uunet!marque,cbosgd,sun!mandrill}!ncoast!allbery >Delphi: ALLBERY MCI Mail: BALLBERY I suggest using the handy dandy little function, snprintf( int count, char *buffer, ) This was proposed as a part of the "Standard C Library". It was reject for various reasons that I am not privy to. I have reached the stage where I have re-implemented a portable version of this that I use wherever I must do SPRINTF. The lack of range and bound checking versions of 'standard' routines in the library routines has been an obstacle to producing portable and bombproof code. Patrick Powell Prof. Patrick Powell, Dept. Computer Science, 136 Lind Hall, 207 Church St. SE, University of Minnesota, Minneapolis, MN 55455 (612)625-3543/625-4002