How to set and get an environment variable in C on Linux?

How to set and get an environment variable in C on Linux?

asked Oct 2, 2013 by anonymous
edited Oct 2, 2013

1 Answer

 
Best answer

You can use the setenv and getenv POSIX APIs to set and get environment variables.

To add or change environment variable:

#include <stdlib.h> 

int setenv(const char *envname, const char *envval, int overwrite);

To get value of an environment variable:

#include <stdlib.h> 

char *getenv(const char *name); 
answered Oct 2, 2013 by anonymous

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...