title: Reading a matrix from file in C doesn't work as expected
body: <p>I would like to read a file like the following into a one-dimensional array which has already been allocated:</p>
  
  <pre><code>   4 4
     1 2 3 4
     5 6 7 8
     9 10 11 12
     13 14 15 16
  </code></pre>
  
  <p>The first line specified the number of rows/columns and is followed by the matrix values. My code is:</p>
  
  <pre><code>int rows, cols;
  infile = fopen("input1.dat", "r");
  fscanf(infile, "%d %d\n", &amp;rows, &amp;cols);
  printf("Rows: %d, Cols: %d\n", rows, cols);
  int i, j;
  double cur = 0;
  for (i = 0; i &lt; m; i++) {
      for (j = 0; j &lt; n; j++) {
          cur = fscanf(infile, "%lf", &amp;cur);
          printf("%lf\n", cur);
          matrix[(i*m)+j] = cur;
      }
  }  
  </code></pre>
  
  <p>Now the output is:</p>
  
  <pre><code>Rows: 4, Cols: 4
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  1.000000
  </code></pre>
  
  <p>I've been searching the site for an hour now but I just can't figure out why none of the values is read, not even from the first line after the row/cols line. Thanks for any help!</p>