title: Print equal-width columns in C using printf formatting
body: <p>I would like to print columns using printf in C. I wrote this code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  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;
  }
  </code></pre>
  
  <p>It works but I have such output:</p>
  
  <pre><code>TXT1:         a TXT2 bbbbbbbeeeeebbbbb TXT3         e
  TXT1:  aaaaaaaa TXT2 bbbbbbbbbbbb TXT3     abcde
  </code></pre>
  
  <p>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?</p>
  
  <p>By saing <em>nice</em> I meant that no matter how long text I pass to my printing function, it will always print out equal-width columns, for example:</p>
  
  <p>I have this output that looks like this: </p>
  
  <pre><code>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  
  </code></pre>
  
  <p>I want it to look like this (no matter how long my text arguments will be):  </p>
  
  <pre><code>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    
  </code></pre>