C Library Function - getenv()
Description
C library function **char getenv(const char name) Search for the environment string pointed to by name and return the associated value as a string.
Declaration
Below is the declaration of the getenv() function.
char *getenv(const char *name)
Parameters
- name -- A C string containing the name of the requested variable.
Return Value
This function returns a null-terminated string containing the value of the requested environment variable. If the environment variable does not exist, it returns NULL.
Example
The following example demonstrates the use of the getenv() function.
#include
#include
int main ()
{
printf("PATH : %s\n", getenv("PATH"));
printf("HOME : %s\n", getenv("HOME"));
printf("ROOT : %s\n", getenv("ROOT"));
return(0);
}
Let's compile and run the above program, which will produce the following result:
PATH : /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
HOME : /
ROOT : (null)
C Standard Library -