Reputation: 107
In C, is there any way to make command line arguments available to other functions without passing them as arguments to the functions?
Upvotes: 0
Views: 291
Reputation: 595961
Some compilers provides global _argc
and _argv
variables for that exact purpose. Or use platform-specific APIs, like GetCommandLine()
and CommandLineToArgvW()
on Windows.
Upvotes: 1
Reputation: 1215
As DaoWen has said, the command-line arguments are just data, available in 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.
Upvotes: 0