Segmentation fault 11?
<p>My program compiles but when I run it <code>./program -n 3 1000.txt</code>, I get </p>

<blockquote>
  <p>segmentation fault: 11. </p>
</blockquote>

<p>What does it mean?</p>

<p>What my program does: print the first 10 lines of the file. If the file has less than 10 lines the entire file should be printed. The program should not create any files. It just prints part of the content of a file to standard output.</p>

<p>It should also be possible to specify that a different number of lines be printed. This will specified by passing the string <code>-n</code> as the first argument to the program, the number of lines to be printed as the second argument and the file as the third argument. </p>

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

int main(int argc, char * argv[]){

int i, n;
char line[1024];
n = atoi(argv[2]);

if(argc == 2){ //eg ./program 1000.txt
    FILE * fPointer;
    fPointer = fopen("1000.txt", "r");
    for(i = 1; i &lt;= 10; i++){
        fgets(line, 1024, fPointer);
        fprintf(fPointer, "%s\n", line);
    }
    fclose(fPointer);
} else if(argc == 4){ //eg ./program -n 4 1000.txt
    FILE * fPointer;
    fPointer = fopen("1000.txt", "r");
    for(i = 1; i &lt;= n; i++){
        fgets(line, 1024, fPointer);
        fprintf(fPointer, "%s\n", line);
    }
    fclose(fPointer);
} else {
    printf("Wrong number of inputs.\n");
}

return 0;

}
</code></pre>