title: Simple Vertical Histogram in C
body: <p>The exercise was to print a histogram of the different characters in the input. At the bottom is my code where I break the different characters into 3 categories a,b, or other, to extrapolate to more categories of characters if the code is successful. But it doesn't have the output I want, for example, for input <code>ab cd</code> I expect</p>
  
  <pre><code>  x
  xxx
  ---
  abo
    t
    h
    e
    r
  </code></pre>
  
  <p>but all I get is </p>
  
  <pre><code>---
  abo
    t
    h
    e
    r
  </code></pre>
  
  <p>Here's my attempt:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  main()
  {
  int i,c,b, max;
  int array[3] = {0,0,0};
  
  
  while( (c = getchar()) != EOF){
      if(c== 'a')
      ++array[0];
      else if(c== 'b')
      ++array[1];
      else if(c=='\n' ||c=='\t' || c==' '){}
      else ++array[2];
      }
  
  array[0]=max;
  i=0;
  
   while(i&lt;3){
      if(max&gt;=array[i])
          {}
      else array[i]=max;
  
      ++i;
   }
  
  i=0;
  max=b;
  while(i&lt;b){
      if(array[0]&gt;=max){
          putchar('x');}
      else putchar(' ');
  
  
      if(array[1]&gt;=max) {
          putchar('x');}
      else putchar(' ');
  
  
      if (array[2]&gt;=max){
          putchar('x\n');}
      else putchar(' \n');
      --max;
      ++i;
  
  
      }
  
  printf("---\nabo\n  t\n  h\n  e\n  r");
  
  
  }
  </code></pre>