Hello,
I'm using strtok to split a string into words. My idea was to follow the word REMOVE
deleted the next word from the text.
void algorithm(node **root, char *line){
char *pch = strtok(line, " ");
while(pch != NULL){
if(strcmp(pch, "REMOVE")==0){
pch = strtok(NULL, " ");
if(pch == NULL){
printf("error?");
}
removeNode(&(*root),pch);
}else{
insert(&(*root), pch);
}
pch = strtok(NULL, " ");
}
}
Why is it that after pch = strtok(NULL, " ");
always has pch = NULL
?
Note: I already tested with large files and a REMOVE there in the middle and the% w /% after this operation always gives% w /%, if the operation is at the end of the cycle the% w /% variable no longer% w /%.