Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the strtok function

Shulou Source: shulou.com Published: 2022-06-03 03:27:18 10月03日 Update

How do I use the strtok function? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

The strtok function is used to decompose a string into a set of strings, and the declaration of the strtok function is "char * strtok (char * str, const char * delim)", where the parameter str represents a string to be decomposed into a set of small strings.

C library function-strtok ()

Description

The C library function char * strtok (char * str, const char * delim) decomposes the string str into a set of strings, with delim as the delimiter.

Statement

The following is the declaration of the strtok () function.

Char * strtok (char * str, const char * delim)

Parameters.

Str-A string to be decomposed into a set of small strings.

Delim-A C string containing delimiters.

Return value

This function returns the first substring that is decomposed, or a null pointer if there is no string to retrieve.

Example

The following example demonstrates the use of the strtok () function.

Example

# include # include int main () {char str [80] = "This is-www.runoob.com-website"; const char s [2] = "-"; char * token; / * get the first substring * / token = strtok (str, s); / * continue to get other substrings * / while (token! = NULL) {printf ("% s\ n", token) Token = strtok (NULL, s);} return (0);}

Let's compile and run the above program, which will produce the following results:

This is the end of This is www.runoob.com website's answer to the question on how to use the strtok function. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.

Tags: Characters strings functions instances questions sizes delimiters parameters more face help answers easy easy content guys partners pointers methods knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi MariaDB Docker Shulou Technology