Afficher un message
Vieux 20/10/2007, 15h57   #6
Charlie Gordon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: simple printf question

"Richard Heathfield" <rjh@see.sig.invalid> a écrit dans le message de news:
CaOdnVqVmdolaYvaRVnyiwA@bt.com...
> 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.


Be careful to cast nchar as (int) if it has a different type, such as
size_t.

--
Chqrlie.


  Réponse avec citation
 
Page generated in 0,05859 seconds with 9 queries