Truncate string by delimiter: how to use strtok
#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;
}
Related examples in the same category