title: Reading file into 2d char array works for 500 lines but not 50,000
body: <p>All I want to do is read the lines of a file into a 2d char array.  I've counted the lines and the number of chars in the longest line (using a function <code>lineCount()</code>).  In my first case, it was 500 lines of max 50 chars.  The second case is 50,000 lines of max 30 chars.  Here is my <code>main()</code>:</p>
  
  <pre><code>int main(int argc, char** argv)
  {
      char fileName[] = "C:\\valid_50K.txt";
  
      int p[2] = { 0, 0 };
      lineCount(&amp;fileName, &amp;p);
  
      uint8_t** lines = (uint8_t**)malloc(sizeof(uint8_t*) * p[0]);
      for (int lnVar = 0; lnVar &lt; p[0]; lnVar++)
      {
          lines[lnVar] = (uint8_t*)malloc(p[1] + 1);
      }
  
      readLines(&amp;fileName, p[1], lines);   
  }
  </code></pre>
  
  <p>and here is <code>readLines()</code>:</p>
  
  <pre><code>void readLines(char* fileName, int numChars, uint8_t** out)
  {
      FILE *fptr = NULL;
      int i = 0;
  
      fptr = fopen(fileName, "r");
  
      while (fgets(out[i], numChars + 1, fptr))
      {
          out[i][strlen(out[i]) - 1] = '\0';
          i++;
      }
  
      fclose(fptr);
  }
  </code></pre>
  
  <p>It works great for 500 lines, but with the 50K I get an error <code>Unhandled exception at 0x00007FFAAD21BC78 (ucrtbase.dll) in test.exe: An invalid parameter was passed to a function that considers invalid parameters fatal</code> on the <code>out[i][strlen(out[i]) - 1] = '\0';</code> line.  The entire file is only 1MB, with only ASCII characters, so I don't understand what the problem is.  I'm using Visual Studio 2017.</p>