passing command line argument

This is a discussion on passing command line argument within the C Programming forums, part of the General Programming Boards category; Hi: int main(int argc, char *argv[]) { if (argv[1] == "go") method(argc, ?????); } /**********************/ void method(int argc, char *argv[]){ ...

  1. #1
    Tim
    Guest

    Red face passing command line argument

    Hi:

    int main(int argc, char *argv[]) {
    if (argv[1] == "go")
    method(argc, ?????);
    }

    /**********************/
    void method(int argc, char *argv[]){
    /*stuff*/
    }



    What should go in ????
    I am trying *argv[], **argv, argv[]
    none of them is working!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > if (argv[1] == "go")

    This won't work. Use 'strcmp', or write your own string comparison function.

    Second, why don't you just pass the string over that you want processed, where 'x' is some number:

    myfunc( argc[x] );

    With the prototype:

    myfun( char * )

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Tim
    Guest
    For the first part, my bad!

    but for the passing the array, I don't know how many arguments the user is going to enter, and I want to pass all of them.

    How do you pass an unkown array to another function, like in the case above?

    Thanks.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Just use the same way that 'main' uses it.

    int main( int argc, char *argv[] )

    Then call it the same way:

    myfun( argc, argv );

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-21-2008, 12:15 PM
  2. function passing argument..array ?
    By jochen in forum C Programming
    Replies: 2
    Last Post: 09-30-2007, 11:53 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Passing function as an argument.
    By hyaku_ in forum C Programming
    Replies: 1
    Last Post: 12-11-2005, 03:43 AM
  5. problem passing an option as command line argument
    By papous in forum C Programming
    Replies: 3
    Last Post: 11-22-2001, 05:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21