C strtok function

The strtok function in C is a String method to parse or tokenize a given string using a delimiter. The syntax of this strtok function is

void *strtok(char *str, const char *delimiter);

strtok in C Language Example

The strtok function is used to tokenize the given string based on the delimiter we gave. This program helps you to understand this method with multiple examples using a while loop.

TIP: You must include the C Programming #include<string.h> header before using this String Function in a program.

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

int main()
{
    char str[] =  "This is xyz working in abc company";
    char *res;
    
    res = strtok(str, " ");
    
    while(res != NULL)
    {
        printf("%s \n", res);
        res = strtok(NULL, " ");
    }
    
    return 0;
}
C strtok function example