Skip to content

Instantly share code, notes, and snippets.

@tobin
Created October 9, 2012 21:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobin/3861703 to your computer and use it in GitHub Desktop.
Save tobin/3861703 to your computer and use it in GitHub Desktop.
The third argument to main()
/* 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;
}
@execat
Copy link

execat commented Dec 6, 2012

Awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment