|
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.
|