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);
  }
}

it complain during compilation.

Post error message and line numbers where the errors occur.

 prog_argv[0] = "/usr/local/bin/ls";

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

You declared this: char *prog_arv[4];
you use this: prog_argv[0]
arv <--> argv

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.

same error sir

Post the new code please.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.