#include //头文件
#include
int main()
{
// char* str = "123,456,789"; // 出错 strtok()函数原型的形参就是char * 类型。
char str[] = "123,456,789"; // 正常
char sep[] = ",";
char* next = NULL;
char* temp = strtok_s(str, sep, &next);
while (temp != NULL)
{
printf("%s", temp);
temp = strtok_s(NULL, ",", &next);
}
system("pause");
return 0;
}
next是个空指针啊,你没有分配空间。用数组的话,就有空间了
你没发现调试的时候sep长度是2吗?
sep[] = {"," }
strtok_s(str, &sep[0], &next);