main( int argc, char** args, char** env )The third argument is a NULL terminated array of environment variables (the same format as char** args in other words. Now, the normal way to find an environment variable would be to call getenv() with the name of the variable you want, but printing the environment variables passed in could be interesting:
#include <iostream>
int main( int argc, char** args, char** env )
{
int i = 0;
while( env[i] != NULL )
{
std::cout << env[i] << std::endl;
i++; }
return 0;
}
No teacher or book ever mentioned that main() can take more than two arguments. My guess is that this is OS dependent. Which would explain why it is never mentioned or explained in books.
I don't immediately see how browsing through the environment variables could be useful, but then I never knew it was possible before... maybe I'll think of a use for it later.What else is out there? How about another NULL terminated list? It looks like this is the command that was called - but why again, this is normally in argv[0]?
#include <iostream>Windows also supports the extra arguments in main.
int main( int argc, char** args, char** env, char** whatisthis )
{
int i = 0;
while( whatisthis[i] != NULL )
{
std::cout << whatisthis[i] << std::endl;
i++; }
return 0;
}
This is my blogchalk: United States, Oklahoma, Tulsa, Midtown, English, Austin Gilbert, Male, 26-30, computer science, photography.