Okay I found something. How could I use this:
Code:
/* strtok example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}
This is my attempt at making it work but it doesn't:
Code:
void Index::addWord(string word, int pageNumber)
{
cout << word;
char * pch;
pch = &word[0];
pch = strtok (pch," :(#;[]""\"()!`'?,.-");
while (pch != NULL)
{
//printf ("%s\n",pch);
pch = strtok (NULL, " :(#;[]""\"()!`'?,.-");
data.push_back(pch);
}
}
I need to take the passed string, split it into a character array, then store the split words into the vector.