for(i=0;i<argc;i++) { cout << i << argv[i] << endl } for(i=0;envp[i]!=NULL;i++) { cout << i << envp[i] << endl }
if(argc > 1 && !strcmp(argv[1],"-e")) { // code to print environment variables. }
bool showArgs=false, showEnv=false; ... for(i=1;i<argc;i++) { if (!strcmp(argv[i],"-e")) { showEnv = true; } else if (!strcmp(argv[i],"-a")) { showArgs=true; } } .... if(showEnv) { // code to print environment variables. }
} else if (!strcmp(argv[i],"-o")) { i++; if (i < argc) { filename = argv[i]; i++; } else { cout << "the option -o requires a file name (string), none given" << endl; } }
for(i=0;envp[i]!=NULL;i++) { line = envp[i]; pos = line.find('='); var = line.substr(0,pos); value = line.substr(pos+1,line.size()); if ((var=="USERNAME") ||(var=="USER")) { cout << endl; if(value =="dbennett" || value=="bennett") { cout << "Hi Dan!" << endl; } else { cout << "Forget the world, Hello " << value << endl; } } }