title: Tokenizing string from dynamic array into multiple lines in static 2D char array
body: <p>I have a dynamic array that holds a string containing '\n' characters, so this string is made up of multiple lines. I'm trying to extract the lines and put them all into a 2D char array and I'm getting segmentation errors.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    char *input_lines = malloc(MAX_LINE_LEN*sizeof(char)); 
      input_lines = extractInput(MAX_LINE_LEN, input_file);
      char inputLines_counted[lineCount_input][MAX_LINE_LEN];
  
  
      char *t = strtok(input_lines, "\n");
      for(i = 0; i &lt; lineCount_input; i++) {
          strcpy(inputLines_counted[i], t);
          // printf("%s\n", inputLines_counted[i]);
          t = strtok(NULL, "\n");
      }
  </code></pre>
  
  <p>Upon creating the dynamic array, I use the <code>extractInput(MAX_LINE_LEN, input_file)</code> function to populate the <code>input_lines</code> array with a string containing multiple lines.</p>
  
  <p>Here's the extract function: </p>
  
  <pre><code>char *extractInput(int len, FILE *file) {
      char tmp[len];
      char *pos;
      char *input_lines = malloc(len*sizeof(char)); 
      char *lines;
      while(fgets(tmp, len, file)) {
          // if((pos = strchr(tmp, '\n')) != NULL) {
          //     *pos = ' ';
          // }
          input_lines = realloc(input_lines, (strlen(input_lines) + len)*sizeof(char));
          strcat(input_lines, tmp);
      }
      return input_lines;
  }
  </code></pre>
  
  <p>Why am I getting segfaults here?</p>