How do I get the list of all environment variables in C and/or C++?
I know that getenv
can be used to read an environment variable, but how do I list th
LPTCH WINAPI GetEnvironmentStrings(void);
http://msdn.microsoft.com/en-us/library/ms683187%28VS.85%29.aspx
EDIT: only works on windows.
#include<stdio.h>
extern char **environ;
int main() {
int i = 1;
char *s = *environ;
for (; s; i++) {
printf("%s\n", s);
s = *(environ+i);
}
return 0;
}
I think you should check environ
. Use "man environ".