The function getenv () in C
Char * getenv (const char * name) function searches the environment string pointed to by the name parameter and returns the value associated with that string.
Char * getenv (const char * name) function searches the environment string pointed to by the name parameter and returns the value associated with that string.
Declare getenv () function in C
Here is the declaration for getenv () in C:
char * getenv ( const char * name )
Parameters
name : This is the string containing the name of the requested variable.
Returns the value
This function returns a string (terminated by null) with the value of the required environment variable, or returns NULL if the environment variable does not exist.
For example
The following C program illustrates the use of getenv () in C:
#include #include int main () { printf ( "PATH : %sn" , getenv ( "PATH" )); printf ( "HOME : %sn" , getenv ( "HOME" )); printf ( "ROOT : %sn" , getenv ( "ROOT" )); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous lesson: Function exit () in C
Next lesson: Function system () in C
4 ★ | 1 Vote
You should read it
- Function realloc () in C
- Malloc () function in C
- Call the function by pointer in C ++
- Pass cursor to function in C ++
- Function abs () in C
- The abort () function in C
- The function rand () in C
- Div () function in C
- Zip () function in Python
- Labs () function in C
- Call the function by value in C ++
- Atof () function in C