Reputation: 59
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]);
}
Upvotes: 1
Views: 2330
Reputation: 3767
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.
Upvotes: 5