How do I read and print the first 5 integers from a .txt file in C? : <p>I'm trying to read and print the first five integers from a .txt file in C. 
I have a few files with lists of varying integers that I need to be able to read, using command line arguments.</p>

<p>For example, if I type</p>

<pre><code>./firstFive 50to100.txt
</code></pre>

<p>[File 50to100.txt contains integers 50-100 separated by a new line]</p>

<p>So the program should print - </p>

<pre><code>50
51
52
53
54
</code></pre>

<p>As there are a few different files to read (all containing integers), I'm using "fp" as a catch all to open a file specified from argv[1].</p>

<p>Here is what I have so far - </p>

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

int main(int argc, char *argv[]) {
FILE *fp;
int num;
int i;

if (argc &lt; 2) {
    fprintf(stderr, "Usage: %s &lt;filename&gt;\n", argv[0]);
    return 1;
}

fp = fopen(argv[1], "r");
if (fp == NULL) {
    fprintf(stderr, "%s: unable to open file %s,\n", argv[0], argv[1]);
    return 1;
}

while (fscanf(fp, "%d", &amp;num) == 1) {
    for(i=0; i&lt;5; i++) {
        printf("%c/n", num[i]);
    }
}

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

<p>At the moment it won't even compile. Any idea on what's going wrong?</p>
