I am writing a program that displays all the information in an array. It should start with the array index in brackets (for example, [2]), and they should be aligned to the right with each other.
if it was just a number, I know what you can do:
printf("%-10d", index);
but placing brackets around this will give the following output
[ 1]
[ 2]
...
[ 10]
[ 11]
when I really want it to be:
[1]
[2]
...
[10]
[11]
How should I do it?
source
share