Created
October 9, 2012 21:58
-
-
Save tobin/3861703 to your computer and use it in GitHub Desktop.
The third argument to main()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* It turns out that the environment pointer is passed to main() | |
as the third argument -- I had no idea! The usual way to get | |
the environment is via an "extern char **environ;" declaration. | |
This program prints out the environment in KEY=VALUE format, | |
one variable per line. | |
*/ | |
#include <stdio.h> | |
int main(int argc, char **argv, char **envp) { | |
while (*envp) | |
printf("%s\n", *envp++); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome.