Posts

Showing posts from February, 2014

c in C

unsetenv is used to delete the  variable name from the environment Syntax : int unsetenv(const char *name); Arguments Passed: name of the variable which you want to remove Return  Value :  Returns zero on success else returns -1 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"); } unsetenv("NAME"); printf("\n value of the environmental variable written is %s",getenv("NAME")); return 0; }

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; }

getenv example in C

Syntax:  char* getenv(const char* name) Arguments Passed: Name of the environmental variable Return Value:  Value of the environmental variable if present else returns null Code: #include<stdio.h> #include<stdlib.h> int  main() { printf("HOME Path :%s\n",getenv("HOME")); printf("ROOT Path :%s\n",getenv("ROOT")); printf("USER :%s\n",getenv("USER")); printf("Present Working Directory: %s\n",getenv("PWD")); return 0; }