-2

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?

user3040019
  • 51
  • 2
  • 10
  • 2
    **Don't** repost questions: [How do I pass this array of c strings correctly?](http://stackoverflow.com/questions/21655310/how-do-i-pass-this-array-of-c-strings-correctly). You still have not included the most important part of this, asked for both there and here. **Post the code that fills the array**. (and do it in the original question). – WhozCraig Feb 09 '14 at 05:56
  • Yeah, i redid it so people could answer it better. – user3040019 Feb 09 '14 at 05:57
  • 1. c[128] declares 129 elements and not 128. 2. Post the code that fills. –  Feb 09 '14 at 06:32

1 Answers1

0

It should work well except you forget to return values in builtin_cmd() and main(). Check out running result on Ideone .

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174