Jacob Jacob - 5 months ago 63
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);