标签:
// crt_strtok.c // compile with: /W3 // In this program, a loop uses strtok // to print all the tokens (separated by commas // or blanks) in the string named "string". // #include <string.h> #include <stdio.h> char string[] = "A string\tof ,,tokens\nand some more tokens"; char seps[] = " ,\t\n"; // 字符‘,‘ ‘\t‘ ‘\n‘都作为分割字符 char *token; int main( void ) { printf( "Tokens:\n" ); // Establish string and get the first token: token = strtok( string, seps ); // C4996 // Note: strtok is deprecated; consider using strtok_s instead while( token != NULL ) { // While there are tokens in "string" printf( " %s\n", token ); // Get next token: token = strtok( NULL, seps ); // C4996 } }
结果:
Tokens: A string of tokens and some more tokens Program ended with exit code: 0
strtok、strtok_s、strtok_r 字符串分割函数
标签:
原文地址:http://www.cnblogs.com/sdlwlxf/p/4354310.html