title: Why inside a loop, scanf() with %d does not wait for the user input in case it received an invalid input previously?
body: <p>I am using what <code>scanf() returns when it gets what is expects or when it doesn't. What happens is it gets stuck in the</code>while()` loop.</p>
  
  <p>To my knowledge <code>test = scanf("%d", &amp;testNum);</code> returns a 1 if it receives a number and a 0 if not.</p>
  
  <p>My code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main(void) {
      while (1) {
          int testNum = 0;
          int test;
          printf("enter input");
          test = scanf("%d", &amp;testNum);
          printf("%d", test);
          if (test == 0) {
              printf("please enter a number");
              testNum = 0;
          }
          else {
              printf("%d", testNum);
          }
      }
      return(0);
  }
  </code></pre>