title: How to match string to execvp in c
body: <p>Hello I need to run a program using <code>execvp()</code> the thing is that im getting a sting as argument 
  and i cant seem to match the syntax of the command to work properly here is the code:</p>
  
  <pre><code>int executeUserCommand(char *command, int runInBackground) {
      pid_t pid;
      int status;
      pid = fork();
      if (pid == 0) {
          //child process
          execvp(command, &amp;command);
          exit(1);
      } else {
         //perent
         if (!runInBackground) {
             waitpid(pid, &amp;status, 0);
             return WEXITSTATUS(status);
         }
      }
      return 0;
  }
  </code></pre>
  
  <p>and i am using <code>executeUserCommand("./test 1 2 3", 0)</code>
  the thing is that the program is running but without the arguments..
  what is the problem and how i solve it?</p>
  
  <p>EDIT:
  i have added two fuctions to help me with the spliting and its still not working.</p>
  
  <pre><code>char *getCommand(char *commandAndArguments) {
      char command[256];
      memset(command,0,MAX_LENGTH_OF_LINE);
      sscanf(commandAndArguments,"%s ", command);
      //strncpy(command, commandAndArguments, command - commandAndArguments);
      return command;
  }
  
  void commandToArrguments(char *stringToSplit) {
    const char *p = stringToSplit;
    int n, len;
    int i = 0;
    for (n = 0; n &lt; MAX_NUMBER_OF_COMMANDS; n++) {
      for (len=0; len &lt; MAX_LENGTH_OF_LINE-1; len++) {
        if (p[0] == '\0') {
          break;
        }
        if (p[0] == ' ') {
          p += 1;
          break;
        }
  
        commandArgumnets[n][len] = *p;
        p++;
      }
      commandArgumnets[n][len] = '\0';
    }
  }
  
  int executeUserCommand(char *command, int runInBackground) {
  pid_t pid;
  int status;
  pid = fork();
  char *commandToExecute = getCommand(command);
  if (pid == 0) {
      //child process
      execvp(commandToExecute, commandArgumnets);
      exit(1);
  } else {
      //perent
      if (!runInBackground) {
          waitpid(pid, &amp;status, 0);
          return WEXITSTATUS(status);
      }
  }
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p><code>commandArgumnets</code> is defined as global and still not working</p>