Mega Code Archive

 
Categories / C / String
 

Truncate string by delimiter

#include <stdio.h> #include <string.h> int main () {   char str[] ="This is a sample string, just testing.";   char *p;      printf ("Split \"%s\" in tokens:\n", str);      p = strtok (str," ");      while (p != NULL)   {     printf ("%s\n", p);     p = strtok (NULL, " ,");   }   return 0; }