C How to read in a file from command line args
<p>My goal is to read in a txt file (small_ramp.txt) then input all the numbers excluding the first into an array.The file has 11 lines of numbers on it, the number 10 on the first line indicating how many numbers are in the file then a following 10 numbers (1-10)<a href="http://i.stack.imgur.com/ufvEn.png" rel="nofollow">Small_ramp.txt</a>. When in command prompt i enter in Stats.exe &lt; small_ramp.txt when executing this command I <a href="http://i.stack.imgur.com/7BPCK.png" rel="nofollow">Error</a> receive this error message.</p>

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

int main(int argc, char* argv[])
{
    int n, i;
    FILE* fpointer;
    double *arr;

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

    if (argc != 2) {
        printf("ERROR: you must specify file name!\n");
        return 1;
    }

    if (!fpointer) {
        perror("File open error!\n");
        return 1;
    }

    fscanf(fpointer, "%d", n);// Scan first line of small_ramp.txt to find array size
    arr = (double*)malloc(sizeof(double) * n);// allocate memory for array with the size given (n)

    while (!feof(fpointer)) {
        fscanf(fpointer, "%lf", arr + 1);
    }

    for (int i = 0; i &lt; n; ++i)
    {
        printf("%lf,", arr[i]);
    }

    fclose(fpointer);
    return 0;
}
</code></pre>

<p>I guess my question is am I reading in the file correctly and if so could someone point me in the right direction for fixing this error?</p>