Ads 468x60px

Thursday, April 26, 2012

How to acess Enviornmental Variable in Linux using cpp

Hi all
        Enviornmental variables can acess through c or cpp code in Linux .I am giving  function which can  retrieve Enviornmental Variables

getenv() :=Used to acess the Enviornmental Varible

Syntax :char* getenv(const char *name) ,where name is the Required env. variable 

Example code :

/* getenv example: getting path */
#include <stdio.h>
#include <stdlib.h>

int main ()
  char * pPath;
  pPath = getenv ("PATH");
  if (pPath!=NULL)
    printf ("The current path is: %s",pPath);
  return 0;


Post a Comment