C language Putenv () function: changing or increasing environment variables
header file:
To define a function:
int putenv (const char * string);
Function Description: Putenv () is used to change or increase the contents of an environment variable. The format of the parameter string is Name=value, and if the environment variable originally existed, the contents of the variable would change depending on the parameter string, otherwise the parameter contents would become the new environment variable.
Return value: Returns 0 for successful execution, or 1 for error occurrence.
Error code: Enomem Not enough memory to configure new environment variable space.
Example
#include <stdlib.h>
Main ()
{
char *p;
if (p = getenv ("user"))
printf ("User =%s\n", p);
Putenv ("User=test");
printf ("user+5s\n", getenv ("USER"));
}
Perform:
C language getenv () function: Get the content of environment variables
header file:
To define a function:
char * getenv (const char *name);
Function Description: getenv () is used to get the contents of the parameter name environment variable. The parameter name is the name of the environment variable, and a pointer to that content is returned if the variable exists. The format of the environment variable is name=value.
Return value: Successful execution returns a pointer to the content, and NULL if no compatible environment variable name is found.
Example
#include <stdlib.h>
Main ()
{
char *p;
if (p = getenv ("user"))
printf ("user =%s\n", p);
Perform: