delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/18/08:32:25

From: Erik Max Francis <max AT alcyone DOT com>
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
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019