Mega Code Archive

 
Categories / C++ Tutorial / String
 

Use strtok() to tokenize a sentence

#include <iostream> #include <cstring> using namespace std; int main() {   char delims[] = "., ?;!";   char str[] = "I like apples, pears, and grapes. Do you?";   char *tok;   tok = strtok(str, delims);   while(tok) {     cout << tok << endl;     tok  = strtok(NULL, delims);   }   return 0; }