Argument Array

In some of the exec*() members, you need to provide an argument array. In fact it is an array of pointer.

Therefore we need two dereferencing (malloc() twice) here.

/* Shell/arguArray.c */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>

int main(int argc,char *argv[])
{ 
    char **argList = (char**) malloc(sizeof(char*) * 3); 
    argList[0] = (char*)malloc(sizeof(char) * 10);     
    strcpy(argList[0],"ls"); 
    argList[1] = (char*)malloc(sizeof(char) * 10);     
    strcpy(argList[1],"-al"); 
    argList[2] = NULL;

    execvp(*argList,argList);
   return 0;
}

results matching ""

    No results matching ""