Jacob Jacob - 7 months ago 95
C Question

Printing all environment variables in C / C++

How do I get the list of all environment variables in C and/or C++. I know that

can be used to read an environment variable, but how do I list them all?


env is available as an argument to main, as envp - a null terminated array of strings:

int main(int argc, char **argv, char** envp)
  char** env;
  for (env = envp; *env != 0; env++)
    char* thisEnv = *env;
    printf("%s\n", thisEnv);