title: Terminate scanf on EOF and ignore strings
body: <p>I am using the following code to scan for integers input from the user until end of line occurs. </p>
  
  <pre><code>while (scanf(" %d", &amp;num) != EOF) {
     printf("Do something")
  }
  </code></pre>
  
  <p>This works as expected until the user inputs a string instead of an integer. The program would then endlessly keep printing <code>Do something</code>. Why is that happening? </p>
  
  <p>How can I stop the loop only when End of line occurs, but ignore string inputs and only perform my logic if integer inputs have occured?</p>