How to count the number of integers in a file in C?
<p>I have this code which reads a file from the first argument to the main and counts the number of integers stored in it.</p>

<pre><code>#include&lt;stdio.h&gt;
#include &lt;sys/wait.h&gt;
#include &lt;stdlib.h&gt;

int array[100000];
int count = 0;
int main(int argc, char* argv[]){
    FILE* file;
    int i;


    file = fopen(argv[1],"r");

    while(!feof(file)){
        fscanf(file, "%d", &amp;array[count]);
        count++;
    }

    for(i=0; i&lt;count; i++){
        printf(" \n a[%d] = %d\n",i,array[i]);
    }
    return 0;
}
</code></pre>

<p>The output when I execute this file is</p>

<pre><code> a[0] = 1

 a[1] = 2

 a[2] = 3

 a[3] = 4

 a[4] = 5

 a[5] = 6

 a[6] = 7

 a[7] = 8

 a[8] = 9

 a[9] = 10

 a[10] = 0
</code></pre>

<p>Why is the value of count one greater than expected?</p>

<p>My input file using "./a.out /home/ghost/Desktop/file.txt" is as follows :</p>

<blockquote>
  <p>1 2 3 4 5 6 7 8 9 10</p>
</blockquote>