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've just finished reading the article "The function getenv () in C" edited by the TipsMake team. You can save the-function-getenv-in-c.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.