test_strtok.c

#include <stdio.h>
#include <string.h>

int main()
{
   char str[] = "This,is,a,sample,string,";
   char* ptr; // pointer

   printf("Before: '%s''\n",str);

   ptr = strtok(str,",");
   while ( ptr != NULL )
   {
      printf("%s\n",ptr);
      ptr = strtok(NULL,",");
   }
   printf("After: '%s''\n",str);
} 

“Split” is a basic operation for string manipulation.
In C++, this split operation can be nicely done with strtok.
strtok is a C’s built-in function for string tokenization.

In this example, a string “This,is,a,sample,string,” is split into five tokens delimited by “,”. In other words,
Original string: “This,is,a,sample,string,”
Delimiter: “,”
Tokens:
This
is
a
sample
string