prev up next   top/contents search

comp.lang.c FAQ list · Question 12.10

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

A: printf("%*d", width, x) will do just what you want. The asterisk in the format specifier indicates that an int value from the argument list will be used for the field width. (Note that in the argument list, the width precedes the value to be printed.) See also question 12.15.

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

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North