Syntax
#include <stdlib.h> char *getenv(const char *varname);Description
getenv searches the list of environment variables for an entry corresponding to varname.
getenv returns a pointer to the environment table entry containing the current string value of varname. The return value is NULL if the given variable is not currently defined or if the system does not support environment variables.
You should copy the string that is returned because it may be written over by a subsequent call to getenv.
In this example, pathvar points to the value of the PATH environment variable.
#include <stdlib.h> int main(void) { char *pathvar; pathvar = getenv("PATH"); if (NULL == pathvar) printf("Environment variable PATH is not defined.\n"); else printf("Path set by environment variable PATH is successfully stored.\n"); return 0; /**************************************************************************** The output should be: Path set by environment variable PATH is successfully stored. ****************************************************************************/ }Related Information