title: How to use execvp()
body: <p>The user will read a line and i will retain the first word as a command for execvp. </p>
  
  <p>Lets say he will type <strong><em>"cat file.txt"</em></strong> ... command will be cat . But i am not sure how to use this <code>execvp()</code>, i read some tutorials but still didn't get it.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      char *buf;
      char command[32];
      char name[32];
      char *pointer;
      char line[80];
      printf("&gt;");
  
      while((buf = readline(""))!=NULL){   
          if (strcmp(buf,"exit")==0)
          break;
  
          if(buf[0]!=NULL)
          add_history(buf);
  
          pointer = strtok(buf, " ");
          if(pointer != NULL){
              strcpy(command, pointer);
          }
  
          pid_t pid;
  
          int  status;
  
          if ((pid = fork()) &lt; 0) {     
              printf("*** ERROR: forking child process failed\n");
              exit(1);
          }
          else if (pid == 0) {          
              if (execvp(command, buf) &lt; 0) {     
                  printf("*** ERROR: exec failed\n");
                  exit(1);
              }
          }
          else                                  
          while (wait(&amp;status) != pid)       
              ;
          free(buf);
          printf("&gt;");
      }///end While
      return 0;
  }
  </code></pre>