 <p>The problem is that your <code>fscanf</code> will never read the newline at the end of the first line. So when it is called the second time, it will fail (returning 0, not EOF) and read nothing, leaving <code>buffer</code> unchanged.</p> <p>You could add a call to <code>fscanf("%*[\n]");</code> at the end of your while loop to skip the newline (and any blank lines that might occur). Or you could just use <code>fgets</code> instead, which also makes it easier to avoid the potential buffer overflow problem.</p>