title: Why does strtok cause a segfault in my program?
body: <p>I'm trying to build a function which takes in two strings of numbers like char <code>strArr[2] = {&quot;1, 2, 3, 4, 5&quot;, &quot;4, 5, 6, 7, 8&quot;}</code> and parses them. While writing my function I got a seg fault, I've identified the exact line that seg faults it, and omitted everything after that line.</p>
  <p>The offending line is a <code>strtok</code> call which takes in the first string and a delimiter to split at. Does anyone know what's going on?</p>
  <p>Code in question:</p>
  <pre><code>void FindIntersection(char * strArr[]) { 
  
  int nel1 = 1;
  int nel2 = 1;
  int i = 0;
  
  /*Determine the number of elements in strArr[0] */
  while(strArr[0][i] != '\0'){
      if(strArr[0][i] == ','){
          nel1++;
      }
      i++;
  }
  
  i = 0;
  /* Determine the number of elements in strArr[1] */
  
  while(strArr[1][i] != '\0'){
      if(strArr[1][i] == ','){
          nel2++;
      }
      i++;
  }
  
  int intArr1[nel1];
  int intArr2[nel2];
  
  /* parse the elements from each char array and place them in int arrays */
  
  char delim[2] = &quot;, &quot;;   
  char *token;
  token = strtok(strArr[0], delim);
  </code></pre>