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
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
Maybe you are interested
Unbelievable coincidence in history makes the whole world astounded How to directly see the phenomenon of super moon, blue moon and eclipse converging after more than 150 years The most anticipated astronomical events of 2017 Learn about extraterrestrial super-Earth - Gliese 581c New discovery of life on planet GJ 1132b, 'Super Earth' is 39 light-years away True moon, snow moon and comet will appear together today