C中的字符串标记化功能
在本节中,我们将看到如何在C中标记字符串。C具有为此的库函数。C库函数char*strtok(char*str,constchar*delim)使用定界符delim将字符串str分成一系列标记。
以下是strtok()函数的声明。
char *strtok(char *str, const char *delim)
它有两个参数。str-此字符串的内容被修改并分解为较小的字符串(令牌),delim-这是包含定界符的C字符串。这些可能因一个呼叫而异。此函数返回指向字符串中找到的第一个标记的指针。如果没有要检索的令牌,则返回空指针。
范例程式码
#include <string.h>
#include <stdio.h>
int main () {
char str[80] = "This is - www.nhooo.com - website";
const char s[2] = "-";
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);
}输出结果
This is www.nhooo.com website
热门推荐
1 潜能开发训练狗狗
2 狗狗多会训练好
3 扣篮训练狗狗
5 狗狗不训练
6 少儿柔术训练狗狗
8 训练好狗狗
9 训练狗狗怎么训
10 狗狗训练猫咪
11 狗狗训练地点
12 两个多月的狗狗怎么训练
13 怎么训练狗狗去厕所拉屎
14 狗狗怎样训练大小便
15 训练狗狗母
16 怎么训练狗狗坐下和握手
17 近视训练狗狗
18 狗狗倒的训练