title: How to stop a C file reading before EOF?
body: <p>I have a file which is a series of numbers that I am reading through C and then storing in an array. There is a new line at the end of the list which the pointer reads and sends to my array, which is problematic.</p>
  
  <p>List of numbers:</p>
  
  <pre><code>9
  8
  6
  5
  23
  42
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>FILE* fichier=NULL;
  fichier = fopen("resultat.txt","r");
  int i=0;
  int ID[50];
  while(fgetc(fichier)!=EOF &amp;&amp; i&lt;50){
      fscanf(fichier,"%d",&amp;ID[i]);
      printf("%d\n",ID[i]);
      i++;
  }
  fclose(fichier);
  </code></pre>
  
  <p>Output I <em>have</em>:</p>
  
  <pre><code>42
  23
  9
  8
  5
  6
  5
  17081006
  </code></pre>
  
  <p>Output I <em>want</em>:</p>
  
  <pre><code>42
  23
  9
  8
  5
  6
  5
  </code></pre>
  
  <p>How can I stop it reading the last (empty except for a return) line?</p>