title: Using while (scanf(...)==0) properly
body: <p>I have a question regarding the use of scanf with the invalid return. Here is a fragment of code I am testing:</p>
  
  <pre><code>printf("Please enter a number\n");
  while (scanf("%d",&amp;number)==0)
  {
      printf("Try again.\n");
      scanf("%d",&amp;number);
  }
  </code></pre>
  
  <p>My reasoning suggests that if an invalid type is used, my second scanf should ask again and test the new entered value. However, this is not the case and the Try again message never stops printing so I have to terminate it manually. I am not sure why this is happening.  I don't want to have to use the scanf before the while loop if possible although I know this is a possible workaround. I would appreciate any help on this matter. Thanks.</p>