Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The first while loop does not give proper results.
But when I changed the declaration of global variable to "extern char ** environ"it gave proper results.
can some one clarify me this as why is this happening. As per my understanding char* environ[] and char** environ are same. And also the second loop worked fine though I declared envp as char * envp[].
2.) When I ran the above program with out passing any command line arguments, it still worked and gave proper results with loop 2, the envp argument. How come? I didnt pass this argument, how could it still pull in the environment variables to envp? And the main thing, if I would like to pass the command line arguments I would I do that?
Thanks a lot in advance.
Last edited by vtn; 08-16-2009 at 07:10 AM.
Reason: corrected the code posted as it diverts the problem
1. This part is tricky. IMO when you add extern char* environ[] you redefine it, in fact. On the other hand, if you use exactly the same extern as in unistd.h, it is just a repeat. In fact, I wouldn't redefine environ (any way), just compile with -D_GNU_SOURCE (if you do not have other reasons to leave it off).
i actually can't say about the problem...i'll figure it out and let you know....
the thing is whenever you write programs, let it be any language, follow proper indentation and proper commenting.
it helps oyhers to grasp your program quickly.
Thanks for your response and I understood what I was doing regarding first loop..thanks.
Regarding the second loop, my question was different...when I ran the code I was running one loop at a time and when I posted it I forgot to initialize i to 0... my bad . Anyways I edited the code I posted. But my question was, after compiling the code and if I run it with out passing the command line arguments like ./a.out at the prompt, envp is still available inside the code. I was assuming it to complain that envp unkown variable when I run it with out passing the arguments.
Also if I need to pass command line arguments when running a program, how would I do it?
Thanks for the suggestion ..but I did maintain the indentation but when I post the code it is getting corrupted and all spaces are being removed. How do I do that.
Thanks
Quote:
Originally Posted by lemon09
i actually can't say about the problem...i'll figure it out and let you know....
the thing is whenever you write programs, let it be any language, follow proper indentation and proper commenting.
it helps oyhers to grasp your program quickly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.