c - Printing int values with a user determined padding? -


this question has answer here:

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

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -