title: How to exit stdin when EOF is reached in C programming
body: <p>I'm having troubles with my program. The aim of it is to read an input of numbers from the user, and when they stop inputting numbers (ctrl-d) it collects the inputted numbers and prints out 'Odd numbers were: blah blah'
  and 'Even numbers were: blah blah'.</p>
  
  <p>I'm having trouble with how to exit the program at EOF and when it feels like I have overcome that problem, another problem occurs which is my program doesn't print the numbers from the array. It only prints 'Odd numbers were:' and 'Even numbers were:'.</p>
  
  <p>Any help is appreciated.
  Thanks</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;math.h&gt;
  int main(void) {
  int n, i, array[1000];
      i=0;
      while (i = getchar() !=EOF) {
          scanf("%d", &amp;array[i]);
          i++;
      }   
      printf("Odd numbers were:");
      i=0 ;
      while(i = getchar() != EOF) { 
          if(array[i]%2!=0) {
              printf(" %d", array[i]);
              i++;
          }
      }
      printf("\nEven numbers were:");
      i=0 ;
      while(i = getchar() !=EOF) { 
          if (array[i]%2==0) {
              printf(" %d", array[i]);
              i++;
          } 
      }
          printf("\n");
  return 0;
  }
  </code></pre>