int  putenv ( const char * envvar );

Create or modify environment variable.
  Adds the specified string variable to the environment of the current process. Because environment accepts only one variable per name, this function can also be used to modify or delete existing environment variables.
  putenv can only modify the environment variables for this process and any process created from this, not the operating system level. Once this process ends the environment variables of the parent process will not be changed by this call.


Null-terminated string containing the name of the variable, an equal sign (=) and the value for the environment variable:
varname=value If varname already existed in the environment its value is substituted. If value is not specified, i.e. "varname=" the environment variable with that name is removed.

Return Value.
  0 if successful.
  -1 in case of error.

  Not defined in ANSI-C. Supported by many compilers.


/* putenv example */
#include <stdio.h>
#include <stdlib.h>

main ()
  char * buffer ;
  buffer = getenv ("RESOURCES");
  if (buffer==NULL)
    putenv ("RESOURCES=www.cplusplus.com");
    puts ("environment variable successfully set");
  else puts ("environment variable already existed");
  return 0;

See also.

© The C++ Resources Network, 2000