This shows you the differences between two versions of the page.
— |
c:stdlib.h:getenv [2024/02/16 01:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== getenv ====== | ||
+ | <code c> | ||
+ | #include <stdlib.h> | ||
+ | char *getenv(const char *name); | ||
+ | </code> | ||
+ | |||
+ | getenv matches the string pointed to by name\\ | ||
+ | |||
+ | returns a pointer to the value in the environment, or NULL if there is no match.\\ | ||
+ | |||
+ | ===== getenv C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * getenv example code | ||
+ | * http://code-reference.com/c/stdlib.h/getenv | ||
+ | */ | ||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | #include <stdlib.h> | ||
+ | |||
+ | int main ( void ) | ||
+ | { | ||
+ | char *env; | ||
+ | env = getenv ("USER"); | ||
+ | if (env!=NULL) { | ||
+ | printf ("Your Username is: %s\n", env); | ||
+ | } | ||
+ | return 0; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== Output ==== | ||
+ | |||
+ | user@host:~$ ./getenv | ||
+ | Your Username is: code-reference.com | ||