Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

re arguments to main

0 views
Skip to first unread message

Adrian Suri

unread,
Apr 6, 2007, 5:06:56 AM4/6/07
to
Hi

just looking into arguments being passed to main, I understand that
int argc is the number of arguments including argv[0] which is the full
path to the executing program, but what is *envp[]
I know its a pointer, but what to ?????????????????


// example code
// By Adrian Suri
#include <Iostream>
using namespace std;

main(int argc, char *argv[], char *envp[])
{
cout << "number of arguments passed to program " <<endl;
cout<<"Total arguments was " <<argc <<endl;
int i;
for (i=0; i<argc;i++ ) {
cout <<argv[i] <<" =argc[" <<i <<"]" <<endl;
// cout <<envp[i] <<endl;
} /* endfor */
return 0;
}


regards

Adrian Suri

Lars Erdmann

unread,
Apr 7, 2007, 4:00:41 AM4/7/07
to
Adrian Suri schrieb:
An array of pointers (just like argv) to each individual environment
string. Please note that envp is not entirely portable between OSses
(instead, use "getenv" or the corresponding OS/2 API DosScanEnv to look
for an individual environment string).
Also note that you can only detect the end of envp by receiving a NULL
pointer:
if (envp[j] == NULL)
break;

argc only gives you the elements of argv.

Lars

0 new messages