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 C 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> 

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 example

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.