This blog is under construction

Monday, 30 April 2012

getenv example in C

Header file:

     char *getenv(const char *name);

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

getenv function C example:

  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;

  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