title: Using pointer to character as the argument of strtok
body: <p>I try to split the string by using <code>strtok</code> function. But the program become failed if i use the pointer to character as the argument of this function.</p>
  
  <p>If i initialize the string as <code>s2</code> or <code>s3</code> the program works well. But if i use pointer to character as <code>s1</code> the program get <code>Segmentation fault (core dumped)</code>.</p>
  
  <pre><code>char *s1 = "1A 2B 3C 4D";
  char s2[] = "1A 2B 3C 4D";
  char s3[20] = "1A 2B 3C 4D";
  </code></pre>
  
  <p>The problem is the other functions, <code>printf</code> and <code>strlen</code> work without failure, but only <code>strtok</code> get error.</p>
  
  <p>The complete code below:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  
  void split_string(char *s) {
      char * token = strtok(s," ");
      while (token != NULL) {
          printf("%s\n", token);
          token = strtok(NULL, " ");
      }
  }
  
  int main()
  {
      char *s1 = "1A 2B 3C 4D";
      char s2[] = "1A 2B 3C 4D";
      char s3[20] = "1A 2B 3C 4D";
      printf("size of s1 = %ld, s2 = %ld, s3 = %ld\n", strlen(s1), strlen(s2), strlen(s3));
      printf("s1: %s\ns2: %s\ns3: %s\n",s1,s2,s3);
      printf("split s2: \n");
      split_string(s2);
      printf("split s3: \n");
      split_string(s3);
      printf("split s1: \n");
      split_string(s1);
      return 0;
  }
  </code></pre>
  
  <p>The result after running:</p>
  
  <pre><code>size of s1 = 11, s2 = 11, s3 = 11
  s1: 1A 2B 3C 4D
  s2: 1A 2B 3C 4D
  s3: 1A 2B 3C 4D
  split s2: 
  1A
  2B
  3C
  4D
  split s3: 
  1A
  2B
  3C
  4D
  split s1: 
  Segmentation fault (core dumped)
  </code></pre>
  
  <p><code>strtok</code> from <code>man</code> page: <code>char *strtok(char *str, const char *delim);</code></p>
  
  <p>Please help to understand this problem. </p>