The C library function char *strtok(char *str, const char *delim) breaks string str into a series of tokens using the delimiter delim.
Following is the declaration for strtok() function.
char *strtok(char *str, const char *delim)
#include <string.h> #include <stdio.h> int main() { char str[80] = "This is, - www.CS262.com! - website"; const char s[15] = " !-,."; char *token; /* get the first token */ token = strtok(str, s); /* walk through other tokens */ while( token != NULL ) { printf( "%s\n", token ); token = strtok(NULL, s); } return(0); }
Result:
This is www CS262 com website
原文:https://www.cnblogs.com/JasperZhao/p/12914706.html