"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.