 <p>Read each line one by one with <a href="http://en.cppreference.com/w/c/io/fgets" rel="nofollow"><code>fgets</code></a> then split them with <a href="http://en.cppreference.com/w/c/string/byte/strtok" rel="nofollow"><code>strtok</code></a> and parse with <a href="http://en.cppreference.com/w/c/string/byte/strtol" rel="nofollow"><code>strtol</code></a>.</p> <p>Something like this:</p> <pre><code>char line[256]; int l = 0; while (fgets(line, sizeof(line), input_file)) { int n = 0; for (char *ptr = strtok(line, " "); ptr != NULL; ptr = strtok(NULL, " ")) { key1[l][n++] = strtol(ptr, NULL, 10); } l++; } </code></pre>