putenv example in C
Use : To change the environmental variable value
Syntax: int putenv(char *string)
Arguments : Takes a string as NAME=VALUE, where NAME is the name of the environmental variable and VALUE is the value of the environmental variable you want to set
If NAME is present in the environment list then replace the value else it will add this to the environmental list
Return Type: 0 on success
-1 if any error
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int result=putenv("NAME=TEST");
if(result==0)
{
printf("\n environmental variable successfully written");
printf("\n value of the environmental variable written is %s",getenv("NAME"));
}else{
printf("\n error in writing the environmental variable");
}
return 0;
}
Syntax: int putenv(char *string)
Arguments : Takes a string as NAME=VALUE, where NAME is the name of the environmental variable and VALUE is the value of the environmental variable you want to set
If NAME is present in the environment list then replace the value else it will add this to the environmental list
Return Type: 0 on success
-1 if any error
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int result=putenv("NAME=TEST");
if(result==0)
{
printf("\n environmental variable successfully written");
printf("\n value of the environmental variable written is %s",getenv("NAME"));
}else{
printf("\n error in writing the environmental variable");
}
return 0;
}
Comments
Post a Comment