[net.lang.c] using environment variables in C programs

aron (11/04/82)

This is a how-to question.  How does one extract an environment variable
from the environment table, in order to make use of it in a C program?

Thanks.

					aron shtull-trauring
					harpo!presby!aron

sjb (11/04/82)

To get the environment variable xxx from within a C program, say:

	char *evar, *getenv();
	.
	.
	.
	evar = getenv("xxx");

I believe xxx must be exported (for sh users)

rich (11/05/82)

Note that getenv() will return NULL if there is no such environment variable
defined or if the variable is set to the null-string (FOO="").

mkg (11/09/82)

cfiB!rich is incorrect about what getenv() returns.
getenv() will return NULL if the requested variable is undefined
and will return a pointer to the value of the variable if it is
defined (yes even if the value is NULL).
   Marsh Gosnell  BTL Piscataway  (201) 981-2758  harpo!whuxlb!mkg