Hi,
I just wrote a program that tokenizes a char array using pointers. The program only needed to work with a space as a delimiter character. I just turned it in and got full credit, but after turning it in I realized that this program only worked if the delimiter character was a space.
My question is, how could I make this program work with every delimiter character?
The function I've shown you below returns a pointer to the next word in the char array. This is what I believe I need to change if it is to work with all delimiter characters.
Thanks!
Code:
char* StringTokenizer::Next(void)
{
pNextWord = pStart;
if (*pStart == '\0') { return NULL; }
while (*pStart != delim)
{
pStart++;
}
if (*pStart == '\0') { return NULL; }
*pStart = '\0';
pStart++;
return pNextWord;
}
The printing loop in main:
// this loop will display the tokens
while ( ( nextWord = tk.Next ( ) ) != NULL )
{
cout << nextWord << endl;
}