To get a specific value, use the getenv () function as follows:
        const char *val;
        val = getenv("PATH");
When you want to get the defined value, retrieve the value of environ
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* environ */
int main(int argc, char **argv)
{
    extern char **environ;
    char **env = environ;
    while(*env) {
        const char *val;
        val = *env;
        if (val) {
            printf("%s\n", val);
        }
        env++;
    }
    return 0;
}
Since val has a name and value concatenated with "=" in the form of "TERM = xterm", it needs to be cut when using it.
Recommended Posts