Splitting a string into words

For this, you would use the strtok function:

char myText[100] = "This is text of movie Jurassic Park";
char *p;
for (p = strtok(myText," "); p != NULL; p = strtok(NULL," ")) {
    st.insert(p);
}

Note that this function modifies the string it’s parsing by adding NUL bytes where the delimiters are.

Leave a Comment