title: How strsep works in C?
body: <p>I'm creating a program that when launched takes in input a command and some arguments with <strong>scanf</strong> and calls <strong>execvp</strong> using those arguments.
  I'm doing this with <strong>strsep</strong>.
  I store the string in an array (char*),then I want to split it and store tokens in a new array (this time it's an array[] so I can use it with the execvp).
  Arguments saved  with <strong>scanf</strong> should be commands for terminal (as <strong>"ls</strong>" with <strong>"-l"</strong> ecc,<strong>"pwd"</strong>... however variables saved in <strong>PATH</strong>) so they are separated by " ". </p>
  
  <pre><code>Ex : 
  
  ./mystring  
  Type arguments : " ls -l "
  </code></pre>
  
  <p>It was an example only to specify which kind of input 'll be.
  I'll do the execvp alone,I need help to split the string in tokens.
  This is the code :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main()
  {
   fflush(NULL); //to clean streams
   printf("type the command to start (and arguments if required) \n");
   char **st;
   char dest[10];
   scanf("%s",*st);
   int i;
   for (i=0;(dest[i]=strsep(st," "))!=NULL;i++)
      continue;
   for (int c=0;c&lt;i;c++) printf(" arg %d : [%s] ",c,dest[c]);
   return 0;
  }
  </code></pre>
  
  <p>Lines 5 and 6 required to call <strong>strsep</strong>,the 10 in <strong>dest[10]</strong> is symbolic.</p>
  
  <p>Line 7 to store the input in st.</p>
  
  <p>Line 9 should split on " " and store command and arguments in <strong>dest[I]</strong>(that I'll pass to execvp).</p>
  
  <p>Line 11 to print what dest has stored.</p>
  
  <p>And this is the sad output :</p>
  
  <pre><code>./mystring 
  type the command to start (and arguments if required) 
  Segmentation fault: 11
  </code></pre>
  
  <p>I don't understand how strsep works, someone can help me?</p>