简体   繁体   English

命令行参数可用于其他功能吗?

[英]Command-line arguments available to other functions?

在C语言中,有什么方法可以使命令行参数可用于其他函数,而不必将其作为参数传递给函数?

Some compilers provides global _argc and _argv variables for that exact purpose. 一些编译器出于该确切目的而提供了全局_argc_argv变量。 Or use platform-specific APIs, like GetCommandLine() and CommandLineToArgvW() on Windows. 或使用特定于平台的API,例如Windows上的GetCommandLine()CommandLineToArgvW()

As DaoWen has said, the command-line arguments are just data, available in main(). 正如DaoWen所说,命令行参数只是数据,可在main()中使用。 So if you don't want to pass a command-line argument as a parameter to another function but you want it available in other functions, you could strcpy()/strncpy() the string into a global string. 因此,如果您不想将命令行参数作为参数传递给另一个函数,但希望在其他函数中使用它,则可以将字符串strcpy()/ strncpy()转换为全局字符串。

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

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