title: Help creating a simple C shell
body: <p>I am new to C and I am trying to create a simple C shell that will allow the user to perform various functions like chdir, cd, exit, mkdir.</p>
  
  <p>I've posted my code below.  Can anyone look through it and see what I am doing wrong?  I am not sure if I am using <code>fork</code> and <code>execcv</code> correctly. Thanks!</p>
  
  <pre><code>include stdio.h
  include stdlib.h
  include unistd.h
  include &lt;string.h&gt;
  include sys/types.h
  
  main() {
      //char *user;
  
      //if ((user = getlogin()) == NULL)
      //    perror("__getlogin1() error");
      //else printf("__getlogin1() returned %s\n", user);
      int j, status;
      int pid, c_pid;
      int i = 0;
      char *tmp, **ap;
      char instring[80]; // store one line of input
      char *argv[10]; // store parameters in the format for execv()
  
      promptstart:
  
      printf("Please enter a commcand:\n");
  
      // read a char at a time and put it in instring[]
      // put a '\0' at the end
      instring[i] = getc(stdin); // stdin is the keyboard
      while (instring[i] != '\n') {
          i++;
          instring[i] = getc(stdin);
      }
      instring[i] = '\0'; // replace '\n' with '\0'
  
      tmp = instring;
      i = 0;
      argv[i] = strsep(&amp;tmp, " \t"); // put first word int argv[0]
      while ((i &lt; 10) &amp;&amp; (argv[i] != '\0')) {
          i++;
          argv[i] = strsep(&amp;tmp, " \t");
      }
  
      // print out the command and options.
      i = 0;
      while (argv[i] != '\0') {
          printf("your entered: %s\n", argv[i++]);
      }
  
      //PLACE ERROR HERE
  
      if ((c_pid = fork()) == 0) {
          for (j = 0; j &lt; 10; j++)
              printf("child (%d) prints %d\n", getpid(), j);
          exit(0);
      } else if (c_pid &gt; 0) {
          c_pid = wait(&amp;status);
          printf("child %d exited with status %d\n", c_pid, status);
      } else {
          execvp(argv[0], argv);
  
      }
      goto promptstart;
  }
  </code></pre>