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 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 exitStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started