getenv()
returns a pointer to an internal environment table. By using
strtok()
, you are modifying the string in the internal table. To avoid this, you must create a copy of the returned string and use this copy for parsing with
strtok()
. You may use something like this:
str1 = strdup(str);
free(str1);