This blog is under construction

Monday 30 April 2012

getenv example in C

Header file:
    stdlib.h

Synopsis:
     char *getenv(const char *name);

Description:
      It returns the environmental string associated with the name on success.  NULL is returned on failure.


getenv function C example:


  #include<stdio.h>
  #include<stdlib.h>
  int main() {
        char *str;
        str = getenv("HOME");
        printf("Environment string associated with HOME:%s\n", str);
        str = getenv("PATH");
        printf("Environ string for PATH:%s\n", str);
        str  = getenv("ROOT");
        printf("Environ string for ROOT:%s\n", str);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Environment string associated with HOME:/home/jp
  Environ string for PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin
  Environ string for ROOT:(null)



No comments:

Post a Comment