Public domain
int main ()
{
int overwrite = 1;
char *test;
test = getenv("TEST");
printf("TEST environment variable is %s \n",
(test != NULL) ? test : "undefined.");
setenv ("TEST", "102030", overwrite);
test = getenv("TEST");
printf("TEST environment variable is %s \n",
(test != NULL) ? test : "undefined.");
unsetenv("TEST");
test = getenv("TEST");
printf("TEST environment variable is %s \n",
(test != NULL) ? test : "undefined.");
}
$ export TEST="hello"
$ ./a.out
TEST environment variable is hello
TEST environment variable is 102030
TEST environment variable is undefined.
$ echo $TEST
hello
BY: Pejman Moghadam
TAG: c, setenv, unsetenv, environment
DATE: 2011-06-02 18:26:42