/* environment.c Jeff Ondich, 4 February 2022 Accessing environment variables in C. Want to see all the environment variables in your current terminal session? Try the "env" command. (And, as always, take a look at "man env" to learn more.) */ #include #include int main(int argc, char *argv[], char *envp[]) { printf("argc=%d\n\n", argc); // Use getenv to read the value of an environment variable char *home_value = getenv("HOME"); printf("HOME=%s\n\n", home_value); // Iterate through the envp array for (char **pointer = envp; *pointer != NULL; ++pointer) { printf("%s\n", *pointer); } return 0; }