title: vC: scan numeric input until EOF
body: <p>I have an assignment, when in C programming language, I have to scan multiple numeric (just integer, if it's not integer, it should exit) values from keyboard. Values are divided by space and input is ended by EOF. I need to further work with these scanned values. I know maximum of putted numbers, I don't know beforehand how many numbers I'll get.</p>
  
  <p>I tried:</p>
  
  <pre><code> while (scanf("%d", &amp;a) == 1 &amp;&amp; count &lt;= 10000 )  {
    eof=a;
    if ( eof=getchar() == EOF ) break;
   ...
  </code></pre>
  
  <p>But it doesn't seem to work as I need (often you have to give EOF twice, but not always, and it sometimes adds 0 to the input). Same happens when I use just:</p>
  
  <pre><code>while (scanf("%d", &amp;a) == 1) {
  </code></pre>
  
  <p>if I try:</p>
  
  <pre><code> while (... &amp;&amp; (a=getchar()) != EOF) {
  </code></pre>
  
  <p>the variable a is rewritten and I can't work with it further.</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: Furthermore, I need to distinguish between EOF and invalid input (something other than number), which I am not sure how to do, because</p>
  
  <pre><code>scanf(...)==1
  </code></pre>
  
  <p>won't do that job.</p>