#include<stdio.h>
#include<string.h>
#include<assert.h>
int main()
{
char arr1[] = "redtouch05@xpu.com.cn";
char buffer[30] = { 0 };
strncpy(buffer, arr1, strlen(arr1));//拷贝arr1内容到buffer中 确保原数组的内容不会被影响
const char* tok = "@.";//设置分隔符
//char* ret=strtok(buffer,tok); //初始化
char* ret = NULL;
//Solution 1:
for (ret = strtok(buffer, tok); ret != NULL; ret=strtok(NULL, tok))
{
printf("%s\n", ret);
}
//Solution 2:
while (ret != NULL)
{
printf("%s\n", ret);
ret = strtok(NULL, tok);
}
return 0;
}
stktok 分隔符函数的应用代码示例
最新推荐文章于 2024-09-03 21:49:34 发布