title: When do we need to clear the scanf buffer?
body: <p>I always thought that the "'\n' in buffer" issue only occurs when we are reading characters, 
  however, I stumbled upon this issue with the following code:</p>
  
  <pre><code>int main(int argc, char** argv){
      int height = 0, width = 0;
  
      while(height &lt; 1 || height &gt; 10|| width &lt; 1 || width &gt; 15){
          printf("Please insert the height(1~10) and width(1~15) of the parallelogram (integers): ");
          if(scanf("%d %d", &amp;height, &amp;width) != 2){
              height = width = 0;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>As above, I'm only reading integers with scanf, 
  but this piece of code still gets stuck in an infinite loop when I input something invalid.
  It's fixed if I clear up the buffer.</p>
  
  <p>So my question is, is this "'\n' in buffer" issue a general thing?
  Or does it only happen for special usages? 
  If it only happens for special usages, is there some general guideline I need to follow?</p>