可能重複:
Memory Allocation char* and char[]Segementation故障(核心轉儲)
爲什麼下面的程序給在運行時分段故障?
#include <stdio.h>
#include <string.h>
#include <malloc.h>
main()
{
char * str = "Have a. nice, day :)";
char * ptr;
ptr = strtok(str, " .,");
printf("%s",ptr);
}
但是,如果我使用char str [] =「有一個很好的一天:)」;它給了我輸出。爲什麼即使strtok定義是char * strcpy(char *,const char *)???我也得到這個錯誤〜