title: C - File to integer matrix with fread reads only first value
body: <p>I have two files with each one containing the values of a square matrix. 
  In my program I want to extract those values and put them in 2d static arrays. I HAVE to use fread (assignment..).Names of the files and size of the matrixes are passed through argv.
  However, only the first value of each matrix is read, so the output with printf is :</p>
  
  <pre><code>2 2 2  and 4 4 4
  2 2 2      4 4 4
  2 2 2      4 4 4
  </code></pre>
  
  <p>Here is my code. I suppose I made a stupid and simple mistake, but I don't which one.</p>
  
  <pre><code>#include&lt;stdio.h&gt;  
  #include&lt;stdlib.h&gt;
  
  
  int main(int argc, char **argv){
  
  
  int i,j;
  int res;
  int n=atoi(argv[3]);
  
  int tab1[n][n];
  int tab2[n][n];
  
  FILE *f1;
  f1=fopen(argv[1],"r");
  if(f1==NULL){
      perror("Error f1");
      return EXIT_FAILURE;
  }
  
  else {
  
      for(i=0;i&lt;n;i++){
          for(j=0;j&lt;n;j++){
              fread(&amp;(tab1[i][j]),sizeof(int),1,f1);
          }
  
  }
  
  
  FILE *f2;
  f2=fopen(argv[2],"r");
  if(f2==NULL){
      perror("Error f2");
      return EXIT_FAILURE;
  }
  
  else {
      for(i=0;i&lt;n;i++){
          for(j=0;j&lt;n;j++){
              fread(&amp;(tab2[i][j]),sizeof(int),1,f2);
          }
      }
      fclose(f2);
  
  
      }
  for(i=0;i&lt;3;i++){
      for(j=0;j&lt;3;j++)
          printf("%d ",tab1[i][j]);
      printf("\n");
  
  }
  
  printf("\n");
  //displaying the matrixes
  for(i=0;i&lt;3;i++){
      for(j=0;j&lt;3;j++)
          printf("%d ",tab2[i][j]);
      printf("\n");
  
  }
  </code></pre>