in output i get string 'b' similar to 'a'.. why is this happening? even though i am storing the string from getenv() function to different char arrays..
Please help, i am completely stuck.
Regards
even though i am storing the string from getenv() function to different char arrays.
.
You are incorrect.
When you use getenv - it returns a pointer to some static data.
That means that calling getenv repeatedly to get the same env data you
will receive the same pointer.
(so the pointers a and b in your code is pointing to
the same data in the environment data area)
You should NOT modify the text at the pointer because you are modifying the actual system data space ( and you certainly should not make the string longer like you
are doing).
refer to the microsoft documentation - or the documenation on this site.
It is NOT advisable to use this function in windows:
getenv operates only on the data structures accessible to the run-time library and not on the environment "segment" created for the process by the operating system. Therefore, programs that use the envp argument to main or wmain may retrieve invalid information.