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 <qapplication.h> #include <qlabel.h> #include "text_display.h" extern char **environ; unsigned int i; QObject *label; QString environString = "This is the process environment.\n"; int main( int argc, char ** argv ) { QApplication a( argc, argv ); textDisplayWidget *w = new textDisplayWidget; label = w->child("TextLabel"); for(i=0; i<(sizeof(environ)); i++) { environString.append("(QString)environ[i]"); environString.append("\n"); } ((QLabel*)label)->setText(environString); w->show(); a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); return a.exec(); } -- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists/archive/suse-programming-e
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