Xref: utzoo comp.lang.c:17089 comp.unix.wizards:15132 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!bzs From: bzs@bu-cs.BU.EDU (Barry Shein) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: How to predict size of outcome of vsprintf? Message-ID: <28874@bu-cs.BU.EDU> Date: 21 Mar 89 19:26:00 GMT References: <993@etnibsd.UUCP> <9872@smoke.BRL.MIL> <28831@bu-cs.BU.EDU> <1618@thor.acc.stolaf.edu> <9979@bloom-beacon.MIT.EDU> Organization: Boston U. Comp. Sci. Lines: 25 In-reply-to: scs@adam.pika.mit.edu's message of 21 Mar 89 04:15:41 GMT Ok, there are two thoughts here: 1. How to find out the number of characters a printf operation will generate. 2. How to limit a printf operation to a buffer size. I suggested the first might be the result of printing to a null pointer (buffer or file.) The second could be solved completely transparently by adding a format effector which indicated the maximum buffer size ("must come first!") Such as using %n# as in: sprintf(buf,"%80#%s",string); /* 80 char buf including \0 */ or sprintf(buf,"%*#%s",BUFSIZ,string); /* BUFSIZ char buf */ Not sure what "%n.m#" or "%#" might indicate (perhaps the latter would just return a count of characters, ie, a zero length buffer?) -Barry Shein, Software Tool & Die