I have a C program that outputs two columns, utterly misaligned. The reason for the misalignment is lengths of words in the first column are very different.
I have an o
Presumably you are using printf
to output the columns in the first place. You can use extra modifiers in your format string to make sure things get aligned.
To give a more in depth example:
printf("%-30s %8s %8s\n", "Name", "Address", "Size");
for (i = 0; i < length; ++i) {
printf("%-30s %08x %8d\n", names[i], addresses[i], sizes[i]);
This would print three columns like this:
Name Address Size
foo 01234567 346
bar 9abcdef0 1024
something-with-a-longer-name 0000abcd 2048