Pls can some one help to debug this command interpreter. Can someone help, it complain during compilation.

     int main(int argc, char *argv[])
    {  

    int status;
      int pid;
      char *prog_arv[4];

      /* Build argument list */

      prog_argv[0] = "/usr/local/bin/ls";
      prog_argv[1] = "-l";
      prog_argv[2] = "/";
      prog_argv[3] = NULL;

      /*
       * Create a process space for the ls  
       */
      if ((pid=fork()) < 0)
      {
        perror ("Fork failed");
        exit(errno);
      }

      if (!pid)
      {
        /* This is the child, so execute the ls */ 
        execvp (prog_argv[0], prog_argv);
      }

      if (pid)
      {
        /* 
         * We're in the parent; let's wait for the child to finish
         */
        waitpid (pid, NULL, 0);
      }
    }






  int status;
  int pid;
  char *prog_arv[4];

  /* Build argument list */

  prog_argv[0] = "/usr/local/bin/ls";
  prog_argv[1] = "-l";
  prog_argv[2] = "/";
  prog_argv[3] = NULL;

  /*
   * Create a process space for the ls  
   */
  if ((pid=fork()) < 0)
  {
    perror ("Fork failed");
    exit(errno);
  }

  if (!pid)
  {
    /* This is the child, so execute the ls */ 
    execvp (prog_argv[0], prog_argv);
  }

  if (pid)
  {
    /* 
     * We're in the parent; let's wait for the child to finish
     */
    waitpid (pid, NULL, 0);
  }
}
 prog_argv[0] = "/usr/local/bin/ls";

 `prog_argv' undeclared (first use this function) --this is the error 
 message

Edited 2 Years Ago by Jokatech

on line 6 you have char *prog_arv[4];
this is like char **prog_arv.
you need to remove * to have char prog_arv[4]; for the way you intend to use the char array.

line 6 is ok as it is. Changing it to **prog_arv would make lines 10-13 errors because of unallocated memory for those pointers.

you need to remove * to have char prog_arv[4];

No, lines 10-13 won't compile if changed like that.

Edited 2 Years Ago by Ancient Dragon

This article has been dead for over six months. Start a new discussion instead.