hi again, i have the following code and it has some problem. after doing strtok for the 1st time, when i print out the value of line[0], it returns "hello -a" which is correct. then after the next strtok in the for loop, the result by printing line[0] changes to "hello" i did not do anything to change the value.. so how did it got modified? isit because i did temp = strtok(line[i], ""); and line[i] got changed in the process? please help thanks!
Code:
char* string;
string = "hello -a | world -b";
char** line;
char** line2;
char* temp;
int i, count;
i = count = 0;
//do malloc for line and line 2...
......
.....
/*count number of separated commands */
for(i = 0; i < strlen(string); i++) {
if(strcmp(string[1], "|") ==0){
sector ++;
}
}
if(sector) {
temp = strtok(string, "|");
while(temp) {
line[i] = temp;
i++;
temp = strtok(NULL, "|");
}
printf("%s", line[0]"); //returns hello -a
for(i = 0; i <= count; i++) {
temp = strtok(line[i], "");
line2[i] = temp;
}
printf("%s", line[0]"); // returns hello
}