PDA

View Full Version : char **environ



jas_atwal
12-10-2007, 05:01 PM
Below is the general syntax for environ. Is char **environ a pointor to a pointor?? I am sure it means something else... please explain..



#include <stdlib.h>
extern char **environ;

CornedBee
12-10-2007, 05:10 PM
Nope, that's exactly what it is. A pointer to a pointer to a char.
Although it is interpreted as a pointer to an array of pointers, each of which points to a C-style string.

Salem
12-10-2007, 05:14 PM
Yes it is.

Use it like you would the char **argv that main() receives.

brewbuck
12-10-2007, 05:21 PM
Below is the general syntax for environ. Is char **environ a pointor to a pointor?? I am sure it means something else... please explain..



#include <stdlib.h>
extern char **environ;


It is a pointer to an array of char pointers. In other words, an array of strings where environ[0] is the first, environ[1] is the second, etc. It is exactly like argv but lists the environment variables instead of the command line arguments.

I would suggest against accessing it directly. You should go through getenv() instead.

jas_atwal
12-10-2007, 08:06 PM
Thank you all for your replies!! I really appreciate