Question: This code keeps giving me a sergetation fault #include #include #define MAX_LINE 80 /* The maximum length command */ int main (void) { char *args[MAX_LINE/2

This code keeps giving me a sergetation fault

#include

#include

#define MAX_LINE 80 /* The maximum length command */

int main (void)

{

char *args[MAX_LINE/2 +1]; /* command line arguments */

int should_run = 1; /* flag to determine when to exit program */

while (should_run) {

printf("CSCI3120>");

fflush(stdout);

char *temp;

char *token;

int i = 0;

scanf("%s", &temp);

token = strtok(temp, " ");

while( token != NULL ){

args[i] = token;

printf(" %s ", token);

token = strtok(NULL, " ");

i = i + 1;

}

int j = 0;

while (i > j){

printf(args[j]);

j = j + 1;

}

/**

*After reading user input, the steps are:

*(1) fork a child process using fork()

*(2) the child process will invoke execvp()

*(3) if command included &, parent will invoke wait()

*/

}

return 0;

}

This code keeps giving me a sergetation fault #include #include #define MAX_LINE

This args array will be passed to the execvp) function, which has the following prototype: execvp (char *command, char *params []) Here, command represents the command to be performed and params stores the to this command. For this project, the execvp( function should be invoked as parameters execvp (args[0], args) Be sure to check whether the user included an & to determine whether or not the parent process is to wait for the child to exit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!