View Single Post
Old Nov 8th, 2006, 3:53 AM   #5
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 894
Rep Power: 4 The Dark is on a distinguished road
Note that this code will only work from within main. If you made a function using this code, the "name" array will go out of scope while the environment is still using it.
I suspect that it what your book was getting at, when you use putenv the pointer you pass in may be used by the runtime library until it the environment value is reset, so using a local variable is a problem. One way to get around this is to use malloc to allocate the space for the memory passed to putenv.
The Dark is offline   Reply With Quote