The ADDRESS environ is represented by four bytes on your architecture. So
sizeof(environ)==4, which explains your observation of only four iterations
of the loop.
To loop through the environ variables correctly, you should use something
like
for (i=0; environ[i]!=NULL; ++i) {...}
-----Original Message-----
From: Steven T. Hatton [mailto:hattons@globalsymmetry.com]
Sent: 25. mars 2003 09:59
To: suse-programming-e@suse.com
Subject: [suse-programming-e] looping through **environ?
Someone provided me this sample code getting the **environ variable from the
system and displaying it. It doesn't seem to work correctly. the body of
the for-loop executes four times. I believe there is far more data
available
than that. Am I correct in that assumption? If so, why is this code not
getting it all. It's been ages since I wrote any C/C++, and I was never
fluent in these languages. I recall that working with pointers can be
tricky. By the example on 58 of Ellis & Stroustrup I am lead to believe the
code below should work. Any suggestions?
#include
On Tuesday 25 March 2003 04:09 am, Hallingstad Håkon wrote:
The ADDRESS environ is represented by four bytes on your architecture. So sizeof(environ)==4, which explains your observation of only four iterations of the loop.
To loop through the environ variables correctly, you should use something like for (i=0; environ[i]!=NULL; ++i) {...}
Ok, I think I get it. The example in Ellis & Stroustrup refers to an _array_ **environ is simply a pointer to a pointer to char. Thanks for the help. That seems to have worked. I can tell it's going to be 'interesting' learning to work with QT. STH
participants (2)
-
Hallingstad Håkon
-
Steven T. Hatton