c program to parsing a string with delimiter in-between [using strtok]

C program to parsing a string with delimiter in-between [using strtok]


#include <stdio.h>

#include <string.h>

int main (void)
{
  char str[] = "neelkanth<delimiter>google<delimiter>stallone";
  char *temp = str;
  char *delim = "<delimiter>";
  char *token;

  do {
    printf("Before Tokenizing : %s\n", temp);
    token = strstr(temp , delim);

    if (token)
      *token = '\0';

    printf("After Tokenizing :%s\n", temp);
    temp = token+strlen(delim);


  }while(token!=NULL);


  return 0;
}


Neelkanth_98$ ./a.out
Before Tokenizing : neelkanth<delimiter>google<delimiter>stallone
After Tokenizing :neelkanth
Before Tokenizing : google<delimiter>stallone
After Tokenizing :google
Before Tokenizing : stallone
After Tokenizing :stallone