C strtok function

The strtok function in C is a String Function, which is to parse or tokenize given string using a delimiter. The syntax of this strtok in C Programming language is

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

strtok in C Language Example

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

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

/* C strtok Function example */
 
#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