FreeStyle4 FreeStyle4 - 1 year ago 166
C Question

Printing number of spaces

Is there a way to specify the number of spaces using a variable?

For example lets say I have a basic print statement:


This will print 5 spaces then the number. Is there a way that would let me declare a variable
var = 5
, and use a variable to determine spacing instead? The reason i'm asking is because I'm trying to control the number of spaces after each iteration of a loop to format data a certain way

Answer Source


 printf("%*d", width, someNumber);

You can find more info by man 3 printf

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download