stdio alignment?

Dec 12, 2009 at 5:28pm
Is there a way in stdio to align my text?

Something like this:
1
2
3
4
int i = 1;
int b = 21;
printf("num:  %align(i)",6);
printf("num:  %align(b)",6);


That would print out:

num: 1
num:21


Or at least something similar that would have similar effects?
Dec 12, 2009 at 5:35pm
printf ( "num: %2d", i ); or printf ( "num: %*d", 2, i );
where 2 is the max number of spaced to add
Last edited on Dec 12, 2009 at 5:36pm
Dec 12, 2009 at 5:41pm
Thankyou :) I love this website
Dec 12, 2009 at 5:44pm
Also can you do the same thing with strings too?
Dec 12, 2009 at 5:45pm
Yes
Dec 12, 2009 at 5:49pm
ok finished

printf("%3d : %6s \n",i+1,color[i]);
Dec 13, 2009 at 1:40am
you can also use minus symbol to make things left justified. %-3d %-30s
you can also set number of decimals for doubles/floats . %0.3d
Topic archived. No new replies allowed.