Mega Code Archive

 
Categories / C / Code Snippets
 

Truncate string by delimiter how to use strtok

#include <stdio.h> #include <string.h> int main () { char str[] ="I Love Clementine, I Like Superman."; char *p; printf ("Split \"%s\" in tokens:\n", str); p = strtok (str," "); while (p != NULL) { printf ("%s\n", p); p = strtok (NULL, " ,"); } return 0; }