title: Read a file and save the lines in an array with c
body: <p>I'm trying to read a given <code>file</code> and write its lines into an <code>array</code>. At first, i'm not <code>dynamically allocating</code> the variable (maze) that will store the lines of the <code>file</code>. This is my <code>code</code> until now.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  
  int main(void)
  {
   
      char c, maze[300][300], buffer[1000] = {'\0'};
      int ch = 0, column, row, columns = 0, rows = 0;
      
      FILE* file = fopen(&quot;boards/0.txt&quot;, &quot;r+&quot;);
  
      if ( file )
      {
          while( fgets(buffer, sizeof(buffer), file) != NULL)
              rows+=1;
      }
      // rows will count the number of rows 
      else
      {
          printf(&quot;There's no such file.\n&quot;);
          exit(1);
      }
      // and  columns  will count the number of columns
      columns = (strlen(buffer) - 1);
  
      // write the content file into an matriz
      for (row = 0; row &lt; rows ; row++)
      {
    
          for (column = 0; column &lt; columns; column++)
          {
            
              if(fscanf(file, &quot;%c&quot;, &amp;maze[row][column]) != 1)
                  exit(1);
  
          }
          
      }
  
      fclose(file);
      // print rows
      for (row = 0; row &lt; rows; row++)
      {
          
          for (column = 0; column &lt; columns; column++)
          {
              printf(&quot;%c&quot;,maze[row][column]);
              
  
          }
          
      }
  
      
      return 0;
  
  }
  </code></pre>
  <p>This is the input file:</p>
  <pre><code>....*.....................
  ..........................
  ........*........*........
  .....*....................
  ...............*....*.....
  ..*.......*...............
  ............*.............
  ..........................
  ..............*...........
  ..................*.......
  ..*.......*......*........
  ....*..*..................
  ...**.....................
  ..........*...............
  ....................*.....
  ..........................
  ....**....................
  ......................*...
  </code></pre>
  <p>The output should be the same, but nothing happens. I understand that I'm supposed to <code>dynamically allocate</code> the <code>array</code>, but I'm not sure how to fit this into the code to make it work.</p>