Truncate string by delimiter: how to use strtok : String Split « String « C / ANSI-C






Truncate string by delimiter: how to use strtok

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

1. Sequentially truncate string if delimiter is found
2.Add spaces to the end of a stringAdd spaces to the end of a string
3.Replace space with dash