I would like to print columns using printf in C. I wrote this code:
#include <stdio.h> void printme(char *txt1, char *txt2, char *txt3) { printf("TXT1: %9s TXT2 %9s TXT3 %9s\n", txt1, txt2, txt3); } int main() { printme("a","bbbbbbbeeeeebbbbb","e"); printme("aaaaaaaa","bbbbbbbbbbbb","abcde"); return 0; } It works but I have such output:
TXT1: a TXT2 bbbbbbbeeeeebbbbb TXT3 e TXT1: aaaaaaaa TXT2 bbbbbbbbbbbb TXT3 abcde So the columns are not equal-width. Basicly, I would like to make it like this, that no matter how long is text in my argument, my function would ALWAYS print out a nice formatted columns. The question is: how can I do this?
By saing nice I meant that no matter how long text I pass to my printing function, it will always print out equal-width columns, for example:
I have this output that looks like this:
a cd` fg ij a cd fg ij a cd fg ij ab cd fg ij ab cd fg i j ab cd fg ij ab cd fg ij ab cde fgh ij ab cde fgh ij I want it to look like this (no matter how long my text arguments will be):
a cd` fg ij a cd fg ij a cd fg ij ab cd fg ij ab cd fg ij ab cd fg ij ab cd fg ij ab cde fgh ij ab cde fgh ij