Sequentially truncate string if delimiter is found : String Split « String « C / ANSI-C






Sequentially truncate string if delimiter is found

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

int main(void)
{
  char *p;

  p = strtok("The summer soldier, the sunshine patriot", " ");
  printf(p);
  do {
    p = strtok('\0', ", ");
    if(p) printf("|%s", p);
  } while(p);

  return 0;
}

           
       








Related examples in the same category

1.Add spaces to the end of a stringAdd spaces to the end of a string
2.Replace space with dash
3.Truncate string by delimiter: how to use strtok Truncate string by delimiter: how to use strtok