strtok切割字符串的介绍
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
//strtok切割字符串
//例如chengzixuan@qq.com
//char* strtok(char* str, const char* sep);
int main()
{
const char* sep = "@.";//分割符
char email[] = "chengzixuan@qq.com";
char cp[30] = { 0 };
strcpy(cp, email);//将原字符串拷贝到一个可修改的空间
//简洁版
char* ret = NULL;
for (ret = strtok(cp, sep); ret != NULL; ret = strtok(NULL, sep))
{
printf("%s\n", ret);
}
//原理
//char* ret = strtok(cp, sep);
//if(ret != NULL)
// printf("%s\n", ret);
//ret = strtok(NULL, sep);
//if (ret != NULL)
// printf("%s\n", ret);
//ret = strtok(NULL, sep);
//if (ret != NULL)
// printf("%s\n", ret);
return 0;
}
原文地址:https://blog.csdn.net/2401_87491435/article/details/143633259
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!