Re: simple printf question
husterk said:
<snip>
> Another more flexible method would be to snprintf() your larger string
> into a temporary string buffer and then output the temporary buffer
> using a standard unformatted printf(). This will allow you to
> dynamically change the size of your output string by supplying a
> variable length for your temporary string buffer in the snprintf()
> routine (which cannot be accomplished using the "%.20s" method
> described by Richard.
There is really no need to go to all that trouble.
printf("%.*s\n", nchars, mystring);
Again, this is documented very clearly in K&R2.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
|