user1205722
user1205722

Reputation: 59

Command-line arguments as functions in C

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

Answers (1)

Barshan Das
Barshan Das

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

Related Questions