title: C - How to store tokens returned by strtok() into an array of char pointers?
body: <p>I have a char pointer to a string taken in from a text file that I would like to split up line by line and store into an array. My code is here:</p>
  
  <pre><code>char * token;
  char * unsplitLines[lines];
  const char * s = "\n";
  
  int i = 0;
  while((token = strtok(rawFile, s)) != NULL)
  {
      printf("%s\n", token);
      char * temp = malloc(20);
      strcpy(temp, token);
      unsplitLines[i] = temp;
      free(temp);
      rawFile = NULL;
      i++;
  }
  </code></pre>
  
  <p>where <code>unsplitLines</code> represents each line in the text file, and <code>rawFile</code> is the entire text file that I'm trying to split up. Each line is at most 15 characters, so I allocated 20 bytes just to be safe. I can get the tokens correctly, but the trouble arises when trying to save it in <code>unsplitLines[i]</code>. Any help would be appreciated.</p>