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]
maspjw@