title: Removing substring from string before calling strtok in C
body: <p>I have a variable that I would like to split into an array of paths:</p>
  
  <pre><code>PATH=/bin:/usr/bin:/usr/local/bin
  </code></pre>
  
  <p>Where the result of the above string would be the following:</p>
  
  <pre><code>[0] -&gt; /bin
  [1] -&gt; /usr/bin
  [2] -&gt; /usr/local/bin
  </code></pre>
  
  <p>If I just call <code>strtok</code> on the string with the delimiter <code>:</code> I get the results:</p>
  
  <pre><code>[0] -&gt; PATH=/bin
  [1] -&gt; /usr/bin
  [2] -&gt; /usr/local/bin
  </code></pre>
  
  <p>But then I still have <code>PATH=</code> as a substring at the first index of the array. I need to find a way to remove <code>PATH=</code> from the string before I call <code>strtok</code>.</p>
  
  <p>Rather than having to reallocate a new array of char without the <code>PATH=</code> substring, I thought I could increment the char pointer to point to the first character after <code>PATH=</code>.</p>
  
  <pre><code>char prefix[] = "PATH=";
  
  if (strstr(str, prefix)) {
      str += strlen(prefix);
  }
  </code></pre>
  
  <p>So now the pointer str points to the first / after <code>PATH=</code>.</p>
  
  <p>Before <code>str += strlen(prefix)</code>:</p>
  
  <pre><code>PATH=/bin:/usr/bin:/usr/local/bin
  ↑
  </code></pre>
  
  <p>After <code>str += strlen(prefix)</code>:</p>
  
  <pre><code>PATH=/bin:/usr/bin:/usr/local/bin
       ↑
  </code></pre>
  
  <p>And I get the following array of paths from <code>strtok</code>.</p>
  
  <pre><code>[0] -&gt; /bin
  [1] -&gt; /usr/bin
  [2] -&gt; /usr/local/bin
  </code></pre>
  
  <p>Would this be considered bad practice in C? Are there any side effects from doing so? Should I take another approach: I.e. allocate a new buffer and copy the value of str into the new buffer without <code>PATH=</code>.</p>