C语言的字符串分割
2018-04-04 11:31
337 查看
The strtok() function returns a pointer to the next "token" in str1, where str2 contains the delimiters that determine the token. strtok() returns NULL if no token is found. In order to convert a string to tokens, the first call to strtok() should have str1 point to the string to be tokenized. All calls after this should have str1 beNULL.
For example: char str[] = "now # is the time for all # good men to come to the # aid of their country";
char delims[] = "#";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
printf( "result is \"%s\"\n", result );
result = strtok( NULL, delims );
}The above code will display the following output: result is "now "
result is " is the time for all "
result is " good men to come to the "
result is " aid of their country"
For example: char str[] = "now # is the time for all # good men to come to the # aid of their country";
char delims[] = "#";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
printf( "result is \"%s\"\n", result );
result = strtok( NULL, delims );
}The above code will display the following output: result is "now "
result is " is the time for all "
result is " good men to come to the "
result is " aid of their country"
相关文章推荐
- C语言分割字符串
- C语言strtok()函数:字符串分割
- C语言的字符串按照指定字符串分割操作
- C语言利用strtok函数实现字符串自由分割
- C语言字符串的分割
- C语言 strtok 字符串分割
- c语言中分割字符串
- C语言strtok()函数:字符串分割
- c语言实现字符串分割
- 字符串分割函数——C语言
- C语言:使用strtok_s()函数简单分割字符串
- C语言比较巧妙的字符串分割程序
- [C语言]字符串处理 - 以指定的字符串分割字符串(支持中文字符)
- C语言_字符串分割
- C语言字符串分割——strtok
- hdu 2072 1106学一波字符串分割,C语言与C++两种方法
- C语言按行读文件及字符串分割
- C语言标准字符串分割
- 在C语言中分割字符串
- C语言的字符串分割 [转]