C语言入门到放弃,char* 和字符数组

为什么函数原型 形参时char * 类型,调用时传char* 出错,传字符数组[ ]就没问题?

#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;
}

错误截图

img

next是个空指针啊,你没有分配空间。用数组的话,就有空间了

你没发现调试的时候sep长度是2吗?
sep[] = {"," }
strtok_s(str, &sep[0], &next);