 <p>You have several problems</p> <ol> <li><p>You don't check if the file opened.</p> <ul> <li><p>After <code>fopen()</code> you must ensure that you can read from the file, if <code>fopen()</code> fails, it returns <code>NULL</code> so a simple</p> <pre><code>if (file == NULL) return -1; </code></pre></li> </ul> <p>would prevent problems in the rest of the program.</p></li> <li><p>Your <code>while</code> loop only contains one statement because it lacks braces.</p> <ul> <li><p>Without the braces your while loop is equivalent to</p> <pre><code>while (fgets(buf, sizeof(buf), file)) { ptr = strtok(buf, "f"); } </code></pre></li> </ul></li> <li><p>You don't check that <code>strtok()</code> returned a non <code>NULL</code> value.</p> <ul> <li><p>If the token is not found in the string, <code>strtok()</code> returns <code>NULL</code>, and you passed the returned pointers to <code>atol</code> anyway. </p> <p>That would cause undefined behavior, and perhaps a segementation fault.</p></li> </ul></li> <li><p>You don't check if there was an argument passed to the program but you still try to compare it to a string. Also potential undefined behavior.</p></li> </ol> <p>I don't know if the following program will do what you need since it's your own program, I just made it safer, avoided undefined behavior</p> <pre><code>#include &lt;ncurses.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;stdio.h&gt; int main(int argc, char * argv[]) { char buf[100]; char *ptr; char *ptr2; char *ptr3; char *ptr4; int a; int b; int c; int d; FILE *file; initscr(); cbreak(); noecho(); if (argc &gt; 1) { file = fopen(argv[1], "r"); if (file == NULL) return -1; while (fgets(buf,100,file) != NULL) { ptr = strtok(str,"f"); ptr2 = strtok(NULL," "); ptr3 = strtok(NULL,"f"); ptr4 = strtok(NULL," "); if (ptr != NULL) a = atoi(ptr); if (ptr2 != NULL) b = atoi(ptr2); if (ptr3 != NULL) c = atoi(ptr3); if (ptr4 != NULL) d = atoi(ptr4); } } refresh(); getchar(); endwin(); return 0; } </code></pre>