title: clearing stdin buffer ?
body: <p>I was writing some code and used fgets to get user input. And then i wrote a loop over my code to keep asking for user input until the user prints quit. But the second time it asked, it wrote "Please enter your input" 2 times instead of 1 , and didn't wait for my input the first time. 
  So, i googled it and found that the stdin buffer was filled and it had to be cleared.
  I found this solution : </p>
  
  <pre><code>void dump_line(FILE * fp) {
      int ch;
      while ((ch = fgetc(fp)) != EOF &amp;&amp; ch != '\n') {
          /* null body */;
      }
  }
  </code></pre>
  
  <p>and then calling from the main function :</p>
  
  <pre><code>dump_line(stdin);
  </code></pre>
  
  <p>I have a very hard time understanding it. As i understand it, it simply assigns "ch" the value of fgetc(stdin) .. I simply cant understand how would assigning fgetc(stdin) to "ch" clear the buffer .
  Thank you very much for your help! </p>