From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: sprintf() string length? Date: Sat, 18 Oct 1997 01:42:30 -0700 Organization: Alcyone Systems Lines: 21 Message-ID: <34487676.77551772@alcyone.com> References: <3 DOT 0 DOT 16 DOT 19971014214406 DOT 2c573b3e AT hem1 DOT passagen DOT se> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Peter Palotas wrote: > Is there a way to find out the length of the string that sprintf() > will > generate, without writing it anywhere? i.e. if I want to dynamically > allocate the storage space for the string this would be very good > (read > essential) to know! Unfortunately, there is no ANSI C way to do this. The method that most people use for "safe" string operations is to do the operations in a Very Large Buffer, then only copy the portion that is appropriate the user buffer handed to the function. Ugly, but it works. -- Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com Alcyone Systems / http://newton.alcyone.com/ San Jose, California, United States / icbm://+37.20.07/-121.53.38 \ "After each war there is a little / less democracy to save." / Brooks Atkinson