I keep running into a problem with reading values of a struct array, where I keep getting a segmentation fault. Here is the code:
int main()
{
/* Get PATH Environment Variable */
char *pathv[MAX_PATHS];
char cmd_line[MAX_ARGS];
struct command_t cmd[3]; //THIS IS THE STRUCT ARRAY
size_t len = 0;
/* Parse The Path */
ParsePath(pathv);
while(1) {
/* Print Continuous Prompt */
PrintPrompt();
/* Read Command Line & Parse It */
ReadCommand(cmd_line);
ParseCommand(cmd_line, cmd); //PASSING IT TO THIS METHOD
}
return 0;
}
int ParseCommand(char *buffer, struct command_t *cmd)
{
char *name = "Test";
cmd[0].name; //IF THIS IS COMMENTED OUT AND THE OTHER LINE AS WELL, PROGRAM RUNS
printf("%s\n", cmd[0].name); //FINE....THESE TWO LINES CAUSE SEG. FAULT
}
struct command_t {
char *name;
int argc;
char *argv[MAX_ARGS];
};
What am I doing wrong? Your help is greatly appreciated.
cmd[0].name?struct command_t.