title: Storing integers from a text file into an integer array
body: <p>I have a problem with an exercise, the statement is the following: </p>
  
  <ul>
  <li>save a matrix with a name <code>matriu[7][10]</code>, Getting the numbers from a file. </li>
  </ul>
  
  <p>Here the text of the file: <code>matrix.txt</code></p>
  
  <pre><code>
  1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,0 ,0 ,1 ,0 ,0 ,0 ,1 ,0 ,1 ,1 ,0 ,0 ,0 ,1 ,0 ,1 ,0 ,0 ,1 ,1 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
  </code></pre> 
  
  <p>Following is the version I did, but it fails. Can someone help me fix?</p>
  
  <pre><code>int main()
  {
      int i;
      char linea[3024];
      int j;
      FILE* file;
      file = fopen("matriu.txt", "r");
      int matriu[7][10];
  
      while (fgets(linea, sizeof(linea), file) != NULL) {
  
          char* token;
  
          token = strtok(linea, ",");
  
          printf("%s\n", token);
  
          while (token != NULL) {
  
              token = strtok(NULL, ",");
  
              if (token != NULL)
  
                  matriu[i][j] = atoi(token);
  
              printf("%s\n", token);
          }
      }
  
      for (i = 0; i &lt; 7; i++) {
          for (j = 0; j &lt; 10; j++) {
              printf("%d\n", matriu[i][j]);
          }
      }
  
      return 0;
  }
  </code></pre>