getenv() — Search for Environment Variables

Format

#include <stdlib.h>
char *getenv(const char *varname);

Language Level: ANSI

Threadsafe: Yes.

Job CCSID Interface: All character data sent to this function is expected to be in the CCSID of the job. All character data returned by this function is in the CCSID of the job. See Understanding CCSIDs and Locales for more information.

Description

The getenv() function searches the list of environment variables for an entry corresponding to varname.

Return Value

The getenv() function returns a pointer to the string containing the value for the specified varname in the current environment. If getenv() cannot find the environment string, NULL is returned, and errno is set to indicate the error.

Example that uses getenv()

#include  <stdlib.h>
#include  <stdio.h>
 
/* Where the environment variable 'PATH' is set to a value. */
 
int main(void)
{
   char *pathvar;
 
   pathvar = getenv("PATH");
   printf("pathvar=%s",pathvar);
}

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]