Hello.
I am trying to use the strtok function to separate individual words and store them in a 2D char array. However, only the first word is stored in the 2D array.
cout << "Enter a string: ";
cin.getline (str, MAX);
//count number to words
char *p = strtok (str, " ");
count = wordCount (p);
cout << "No of words = " << count;
cout << endl;
//tokenize string and copy it to 2d array
for (int i = 0; i < count; i++)
{
while (p != NULL)
{
strcpy ( strWords[i] , p);
p = strtok (NULL, ".,? ;");
}
}
for (int i = 0; i < count; i++)
{
cout << strWords[i] << " ";
cout << endl;
}