C library functions - strtok ()
C standard library - <string.h>
description
C library functionschar * strtok (char * str, const char * delim) decomposed into a set of string string str,delim as the delimiter.
statement
Here is () statement strtok function.
char *strtok(char *str, const char *delim)
parameter
- str - to be broken down into a set of strings of small strings.
- delim - C string containing the separator.
return value
This function returns the decomposed last substring, if no search string, it returns a null pointer.
Examples
The following example demonstrates the strtok () function is used.
#include <string.h> #include <stdio.h> int main() { const char str[80] = "This is - www.w3cschool.cc - website"; const char s[2] = "-"; char *token; /* 获取第一个子字符串 */ token = strtok(str, s); /* 继续获取其他的子字符串 */ while( token != NULL ) { printf( " %s\n", token ); token = strtok(NULL, s); } return(0); }
Let's compile and run the above program, which will result in the following:
This is www.w3cschool.cc website