title: C loop won't exit
body: <p>Good-morning one and all!
  This is going to end up being one of those blindingly-easy questions in hindsight, but for the life of me I'm stumped.  I'm going through some of the exercises in The C Programming Language, and I've managed to write some code to initialize a loop.  After some Googling, I found better ways of initializing a loop to 0, but I don't understand why the loop that I wrote to do it doesn't finish. I've used the debugger to find out that it's because the 'c' variable never reaches 50, it gets to 49 and then rolls over to 0, but I can't figure out why it's rolling over. The code is attached below, does anyone know what's going on here?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define IN 1
  #define OUT 0
  
  /* Write a program to print a histogram of the lengths of words in
      itsinput. */
  main()
  {
      int c=0;
      int histogram[50]={0}
      int current_length=0;
      int state=OUT;
  
      //Here we borrow C so we don't have to use i
      printf("Initializing...\n");
      while(c&lt;51){
          histogram[c] =0;
          c=c+1;
      }
      c=0;
      printf("Done\n");
  
      while( (c=getchar()) != EOF){
          if( (c==32 || c==10) &amp;&amp; state==IN ){
              //End of word
              state=OUT;
              histogram[current_length++];
          }else if( (c&gt;=33 &amp;&amp; c&lt;=126) &amp;&amp; state==OUT ){
              //Start of word
              state=IN;
              current_length=0;
          }else if( (c&gt;=33 &amp;&amp; c&lt;=126) &amp;&amp; state==IN ){
              //In a word
              current_length++;
          } else {
              //Not in a word
              //Example, "  " or " \n "
              ;
          }
      }
  
      //Print the histogram
      //Recycle current_length to hold the length of the longest word
      //Find longest word
      for( c=0; c&lt;50; c++){
          if( c&gt;histogram[c] )
              current_length=histogram[c];
      }
      for( c=current_length; c&gt;=0; c--){
          for( state=0; state&lt;=50; state++){
              if( histogram[c]&gt;=current_length )
                  printf("_");
              else
                  printf(" ");
          }
      }
  }
  </code></pre>