c - Printing int values with a user determined padding? -
this question has answer here:
- set variable text column width in printf 2 answers
i'm pretty sure there's no way this, wondering, here goes...
say several int values user, , know fact 1st value largest. way can use length of first int value padding when printing rest of numbers?
browsing forum found can determine length of int (n) this:
l = (int) log10(n) + 1;
using padding of 5 print like:
printf("%5d", n);
so want know whether or not there's way use l instead of 5...
thank you!
do so:
int n = <some value>; int = (int) log10(n) + 1; printf("%*d", i, n);
the *
serves placeholder width being passed argument printf()
.
Comments
Post a Comment