title: Splitting a string with strtok_s
body: <p>I am trying to split a string by a specified delimiter according to this example: <a href="http://msdn.microsoft.com/en-us/library/ftsafwz3(v=VS.90).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ftsafwz3(v=VS.90).aspx</a></p>
  
  <p>My code compiles without errors in Visual C++ 2010, but when I want to run it, I get this error message:</p>
  
  <blockquote>
    <p>Unhandled exception at 0x773a15de in Test.exe: 0xC0000005: Access violation reading location 0x00000000.</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;regex&gt;
  
  using namespace std;
  
  vector&lt;char *&gt; splitString(char in[])
  {
  vector&lt;char *&gt; parts(15);
  char seps[]   = " ,\t\n";
  char *next_token1 = NULL;
  char *token1 = NULL;
  token1 = strtok_s(in, seps, &amp;next_token1);
  while ((token1 != NULL))
  {
      if (token1 != NULL)
      {
          token1 = strtok_s( NULL, seps, &amp;next_token1);
                      //printf( " %s\n", token1 );
          parts.push_back(token1);
      }
  }
  return parts;
  }
  
  int main(int argc, char * argv[])
  {
  char string1[] =
      "A string\tof ,,tokens\nand some  more tokens";
  vector&lt;char *&gt; parts=splitString(string1);
  cout &lt;&lt; parts[0] &lt;&lt;endl;
  cout &lt;&lt; parts[1] &lt;&lt;endl;
  return 0;
  }
  </code></pre>
  
  <p>It seems to be illegal that I try to display the vector's elements, but why?</p>
  
  <p>The vector's capacity should be sufficient and a</p>
  
  <blockquote>
    <p>printf( " %s\n", token1 );</p>
  </blockquote>
  
  <p>in the while loop prints out the tokens!</p>