简体   繁体   English

命令行参数作为C中的函数

[英]Command-line arguments as functions in C

Can I directly use command-line arguments as parameters for other functions which I call in main() ? 我可以直接使用命令行参数作为在main()调用的其他函数的参数吗? Something like: 就像是:

int main(int argc, char* argv[]) {
    somefunction(argv[2], argv[3]);
}

The command line arguments are arguments of main. 命令行参数是main的参数。 Suppose a function like this: 假设这样的函数:

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

Here a and s are arguments to function func1. 这里a和s是函数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. 因此,您的问题的答案恰恰是:是的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM