You can do this as follows:
printf("%*d", width, value);
From Lee's comment:
You can also use a * for the precision:
printf("%*.*f", width, precision, value);
Note that both width
and precision
must have type int
as expected by printf
for the *
arguments, type size_t
is inappropriate as it may have a different size and representation on the target platform.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…