getenv
char *  getenv ( const char * varname );
stdlib.h
  cplusplus.com  

Get string from environment.
  Gets a pointer to the null-terminated string containing the value of the environment variable which name is specified in varname. If the requested variable is not defined in the environment the function returns a NULL pointer.
  The returned pointer is not intended for modifying operations on the environment variable. Refer to putenv or your platform's manual for that.

Parameters.

varname
Null-terminated string containing the name of the requested variable.

Return Value.
  A null-terminated string with the value of the requested environment variable or NULL if that environment variable does not exist.
  Do not use this returned pointer to modify directly the environment variable from your program.

Portability.
  Defined in ANSI-C. Depending on system this function may or not be case sensitive.

Example.

/* getenv example: getting path */
#include <stdio.h>
#include <stdlib.h>

main ()
{
  char * buffer;
  buffer = getenv ("PATH");
  if (buffer!=NULL)
    printf ("Current path is: %s",buffer);
  return 0;
}
The example above shows the PATH environment variable on screen.

See also.
  putenv


© The C++ Resources Network, 2000