title: Tokenize user input for execvp() in c
body: <pre><code>fgets(command, BUFFSIZE, stdin);
  command[strlen(command)-1] = '\0';
  
  char *p = strtok(command, " ");
  char *command_tok[BUFFSIZE];
  int i = 0;
  while (p) {
      command_tok[i++] = p;
      p = strtok(NULL, " ");
  }
  
  
  char *commands[] = {*command_tok, NULL};
  execvp(command_tok[0], commands);
  </code></pre>
  
  <p>I try to get user's input, tokenize it and store command and arguments in an array to pass it to execvp(). However, the arguments are never read. If the input is "ls -l", it is always executed as "ls".</p>