hello, i have the following code... in order to resolve strtok problem, i made a duplicate copy of cmdList named cmdListDup and did a strtok on cmdListDup instead... why am i still getting a modified cmdList after the last loop? :/
Code:/* concatenate command and get command count */ for(i = 0; i < cmdWords; i++) { strcat(cmdStr, words[i]); strcat(cmdStr, " "); if(strcmp(words[i], "|") == 0 ) { cmdCount ++; } } /* Remove | */ temp = strtok(cmdStr, "|"); i = 0; while(temp) { cmdList[i] = temp; cmdListDup[i] = temp; /* duplicate of cmdlist */ temp = strtok(NULL, "|"); i++; } printf("cmd b4 forloop:%s\n", cmdList[0]); //prints cmd b4 forloop: hello -a /* get command for each commands */ for(i = 0; i <= cmdCount; i++) { temp = strtok(cmdListDup[i], " "); cmd[i] = temp; printf("cmd:%s\n", cmd[i]); } printf("cmd after forloop:%s\n", cmdList[0]); //prints cmd afer forloop: hello



LinkBack URL
About LinkBacks



