C Program to tokenize a string Without using Strtok

Logic :
         To tokenize a string without using strtok we will simply use assignment operator '='. The logic is that where the character is found (on basis of which you want to tokenize) place there a '\n' this will print that string in tokens.

Code :

#include<stdio.h>
#include<stdlib.h>
void main()
{
    char arr[100];
    char reverse[100][100];
    int i=0,len=0,j=0;

    printf("Enter string: ");
    gets(arr);

     len = strlen(arr);


     for(i=0; i<len; i++)
        {
            if(arr[i]==' ')  // here in ' ' is the character upon basis of which you want to tokenize in this code there is space
            {
               arr[i]='\n' ;
            }
        }
     puts(arr);
}

Post a Comment

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