Print n spaces
printf has a width specification format that allows you to pass an int to specify the width. If the number of spaces, n , is greater than zero:
printf("%*c", n, ' ');
gotta do the trick. This also holds true for me, you can do this for n greater than or equal to zero with:
printf("%*s", n, "");
Print 1, 6, 11, ... pattern
I still donβt quite understand what you want, but to create the exact template that you described at the bottom of your post, you can do this:
for (i=1; i<=31; i+=5) printf("%3d ", i); printf("\n"); for (i=1; i<=31; i+=5) printf(" | "); printf("\n");
It is output:
1 6 11 16 21 26 31 | | | | | | |
ldgabbay
source share