C - Enumerating all environment variables ========================================= Public domain ******************************************************************************** ### Using 'environ' variable #include /* The 'environ' variable points to an array of * pointers to strings called the "environment" */ extern char** environ; int main() { char **var; for (var = environ; *var != NULL; var++) printf ("%s\n", *var); return 0; } ******************************************************************************** ### Using third argument of the main function _This is not compatible with POSIX.1, so to be portable do not use this_ #include /* Unix systems, and the GNU system, pass * the initial value of environ as the third * argument to main */ int main (int argc, char *argv[], char *envp[]) { for (; *envp != NULL; envp++) printf ("%s\n",*envp); return 0; } ******************************************************************************** _BY: Pejman Moghadam_ _TAG: c, environ, envp, environment_ _DATE: 2011-06-02 10:30:06_