#include <string.h>
#include <stdio.h>
int main()
{
char *p;
char str[100]="This is a test ,and you can use it";
p = strtok(str," "); // 注意,此时得到的 p为指向字符串:"This",即在第一个分隔 符前面的字符串,即每次找到一个分隔符后,一个空(NULL)就被放到分隔符处,所以此时NULL指针指向后面的字符串:"is a test ,and you can use it"。
printf("%s/n",p); // 此时显示:This
do
{
p = strtok(NULL, ","); // NULL 即为上面返回的指针,即字符串:
// "is a test ,and you can use it"。
if(p)
printf("|%s",p);
}while(p);
system("pause");
return 0;
}
strtok
最新推荐文章于 2025-03-05 18:07:14 发布