title: While scanf EOF loop misbehaving
body: <p>I'm a beginner in C, and I've got problem I can't figure out, and wasn't able to find a solution on other threads here.</p>
  
  <p>I'm trying to read integers from a keyboard input/ txt file with the following code:</p>
  
  <pre><code>int grades[MAX_GRADES_LENGTH]={0}, histogram[HISTOGRAM_SIZE]={0};
  int maxGradesHistogramBucket=0, median=0, gradesLength=0;
  double avg=0.0;
  int grade=0;
  
  printf("Enter grades:\n");
  while (scanf("%d",&amp;grade) != EOF)
  {
      grades[gradesLength]=grade;
     gradesLength=gradesLength+1;
  }
  </code></pre>
  
  <p>I'm supposed to set these "grades" in the grades[] array and count the length of the array along the loop.</p>
  
  <p>Somehow the loop is misbehaving, it seems that some inputs are ok with the loop, but for some inputs(most of them actually) the scanf() doesn't get the EOF, whether it's an actual end of file, or the ^D command in the terminal.</p>
  
  <p>I've heard the scanf() is not the most reliable method to read data, but unfortunately I can't use anything else since we haven't learned any other method in class so we can only use scanf() on our homework.</p>
  
  <p>I've tried to change the<code>!= EOF</code> with <code>== 1</code> and its all the same.</p>
  
  <p>for the input </p>
  
  <blockquote>
    <p>100 0 90 10 80 20 70 30 60 40 50</p>
  </blockquote>
  
  <p>for example it works fine.
  but for the input:</p>
  
  <blockquote>
    <p>0 50 100</p>
  </blockquote>
  
  <p>the loop is infinite.</p>
  
  <p>I'm using a macbook pro btw (if it matters).</p>
  
  <p>Any ideas?</p>