1

Can I directly use command-line arguments as parameters for other functions which I call in main()? Something like:

int main(int argc, char* argv[]) {
    somefunction(argv[2], argv[3]);
}
2
  • 3
    There are some online c compilers, such as ideone - check it out. Commented Mar 14, 2012 at 14:40
  • 1
    sure, why not? Just make sure that argc >= 4 (in your example) Commented Mar 14, 2012 at 14:40

1 Answer 1

5

The command line arguments are arguments of main. Suppose a function like this:

func1(int a, char *s[])
{
}

Here a and s are arguments to function func1. They behave like local variables in the function. Now you can pass these variables to another function. (like this: )

func1(int a, char *s[])
{
        func2(a, s);
}

So, answer to your question precisely is : yes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.