_sluimers_
March 2nd, 2006, 06:10 AM
vector<char*> * Program::StringSplit(char * str, char * delim){
vector<char*> * results = new vector<char*>;
char * word;
word = strtok (str,delim);
results->push_back(word);
while (word != NULL){
word = strtok (NULL, delim);
if(word != NULL){
results->push_back(word);
}
}
return results;
}
It works with a string of one word and sometimes two.
Using more words and one of the words are no longer accurate.
But when using 7 words this is the first line of the very long error I get:
*** glibc detected *** ./shell: free(): invalid next size (normal): 0x08264300 ***
I'm not that good at programmnig. All I know is that is has memory problems.
What is wrong with this code and how should it be fixed in order to correctly split
strings?
vector<char*> * results = new vector<char*>;
char * word;
word = strtok (str,delim);
results->push_back(word);
while (word != NULL){
word = strtok (NULL, delim);
if(word != NULL){
results->push_back(word);
}
}
return results;
}
It works with a string of one word and sometimes two.
Using more words and one of the words are no longer accurate.
But when using 7 words this is the first line of the very long error I get:
*** glibc detected *** ./shell: free(): invalid next size (normal): 0x08264300 ***
I'm not that good at programmnig. All I know is that is has memory problems.
What is wrong with this code and how should it be fixed in order to correctly split
strings?