C Program to tokenize a string using Strtok

Strtok is the built-in function of <String.h> header file.

Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main ()
{
char input[100], *tokenptr;
int lenth,i=0,j,temp,count=0;
printf("Enter string to Tokenize : ");
gets(input);

lenth=strlen(input);                      //calculating length of string by built in function
tokenptr=strtok(input, " ");           // tokenizing string on bases of space
while(tokenptr!=NULL)               // while loop until null character is found
{
printf("%s \n",tokenptr);    //printing token
tokenptr=strtok(NULL, " "); //passing NULL as the first parameter to tell function to resume from the last spot left in the string.

   }

Post a Comment

CodeNirvana
Newer Posts Older Posts
© Copyright Encyclopedia of C | Designed By Code Nirvana
Back To Top