title: Reading file content line by line into a matrix
body: <p>I was trying to write a function that could copy a text file content line by line to a matrix, so this is what I came up with:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define rows 5
  #define columns 12
  
  void file_to_matrix(char *matrix[]){
      FILE *file = fopen("swamp.txt", "r");
  
      if(file==NULL){
          printf("File error");
          exit(1);
      }
  
      int y=0;
  
      for(int x=0; (matrix[y][x]=fgetc(file))!=EOF; ++x){
          if(matrix[y][x]=='\n'){
              ++y;
              x=0;
          }
      }
  
      fclose(file);
  }
  
  int main(){
      char *matrix[rows];
  
      file_to_matrix(matrix);
  
      for(int i=0; i&lt;5; ++i){
          for(int j = 0; j &lt; 11; j++){
              printf("%c", matrix[i][j]);
          }
          printf("\n");
      }
  }
  </code></pre>
  
  <p>I tried to compile and run it on Windows and Linux but the only thing that it manages to do is giving me errors that are practically useless like:</p>
  
  <pre><code>"Stopping due to fatal error: NullReferenceException: Object reference not set to an instance of an object"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>"Segmentation fault (core dumped)"
  </code></pre>