I already asked this question and did a very poor job posting it leading to confusing answers that did not help me solve my problem whatsoever. This time ill be trying harder to make my question easier to address. Here is the problem below...
int builtin_cmd(char **argv);
int main()
{
char *argv[128]; //create an array of c_strings with 128 slots in the array
//put 'quit' into argv[0].. (This was done by another file given to me by the professor)
printf("%s\n", argv[0]); //prints 'quit', as it should
builtin_cmd(argv); //call builtin_cmd and pass argv to the function
}
int builtin_cmd(char **argv)
{
printf("%s\n", argv[0]); //prints nothing, should have printed 'quit'
}
Basically the issue that I am having is accessing char *argv[128]
in the function builtin_cmd
. I set the first index in the array to the c_string 'quit' and print it right there and it works just as I expected it too the printf() prints out 'quit' in the terminal. However, once I call builtin_cmd(argv);
the line printf("%s\n", argv[0]);
prints absolutely nothing as if the argv was empty. How am i supposed to correctly pass argv into the function builtin_cmd?