title: Removing multiple blanks using putchar and getchar in C
body: <p>Problem: Write a program that receives textual input using <code>getchar()</code> and outputs the string, having removed multiples blanks. </p>
  
  <p>Here's how I wrote the pseudo-code:</p>
  
  <pre><code>While each input character is received before reaching EOF, do the following:
       1) if character is non-blank, print it out
       2) otherwise:
           a. print out the blank
           b. do nothing untill the next non-blank character 
       3) if a non-blank character is reached, go back to 1)
  </code></pre>
  
  <p>I tried to implement the algorithm as such:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  /* replaces multiple blanks with a single blank */
  main(){
      char c;
      while((c= getchar())!=EOF){
          if (c != ' ')
              putchar(c);
          else {
              putchar(c);
              while(c == ' ')
                  ;
          }
      }   
  }
  </code></pre>
  
  <p>When a string contains blanks, it stalls. I am not sure how I should debug it. I think the problem is with my second <code>while</code>, and the program gets into an infinite loop there rather than waiting for the new characters. </p>