-
Command line argument
In most of c++ books I have found arg as
Code:
int main(int argc,char * argv[])
Is it necessary that int variable name must be argc only and char* name must be argv only. Though on Turbo c++(3) I am able to use any name but I suspect that it should only be argc and argv.
-
I don't think so.
:: Edit
I did a test, and you can name them whatever you like. I guess it's just convention.
-
Call them whatever you want, but you're sure to attract comments if you defy this particular convention.
-
one more ques.
What will be output and why?
Code:
//myprog.exe
int main(int argc,char* argv[],char* env[])
{
for(int i=1;i<argc;++i)
cout<<env[i];
}
return(0);
}
if command line arg is
[code]
myprog.exe one two three
-
It wont compile in the first place due to a syntax error. Other than that it probably depends on your system, since the C++ standard doesnt specify what the additional arguments to main() should be (besides argc and argv).
-
Assuming your run-time passes a third argument to main() called envp, you should note that argc doesn't count how many environment variables you have.
for ( i = 0 ; envp[i] != NULL ; i++ )
Is how you step through it.