Next: Escape characters for Up: Finer control of Previous: Field widths

Dynamic control of field width

You can use "*" to say "use the next argument (which must be an integer) as the field width".

Example

    printf("%.*s", max, s);

prints at most "max" characters from string s.

[The decimal point is needed because %*s allows the field to expand beyond +verb+max+. For strings, the precision values have a special interpretation: see the recommended book]



Next: Escape characters for Up: Finer control of Previous: Field widths


maspjw@
Tue Sep 27 15:29:34 BST 1994