我正在学习C标准函数的字符串操作.当我学习这些东西时,我面临着strtok函数和以下代码.
#include <string.h>
#include <stdio.h>
int main()
{
char str[80] = "This is - www.tutorialspoint.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);
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么在while循环中,strtok与null一起使用?为什么在这里使用null?因为在strtok函数定义中有类似的东西(这个函数使用第二个参数将第一个参数字符串分解为一系列标记.)