Question 12.10

How can I implement a variable field width with printf? That is, instead of %8d, I want the width to be specified at run time.


printf("%*d", width, n) will do just what you want. See also question 12.15.

References: K&R1 Sec. 7.3
K&R2 Sec. 7.2
ANSI Sec. 4.9.6.1
ISO Sec. 7.9.6.1
H&S Sec. 15.11.6
CT&P Sec. A.1


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback