作者apiod ( )
看板C_and_CPP
標題[問題] strtok
時間Mon May 3 14:26:29 2010
char pA[]="Content-type: text/html\n\nThis is a pen";
如果我把pA[]改成*pA,編譯就會出現Segmentation fault
為什麼不能寫*pA?
這樣就沒辦法跟strstr一起用了欸=.=
char *p;
char *delim="/\n";
strtok(pA, delim);
p = strtok(NULL, delim);
printf("%s", p);
感謝解惑~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.251.183.145
※ 編輯: apiod 來自: 60.251.183.145 (05/03 14:32)
→ james732:置底文十二誡第四 05/03 14:49
推 freesamael:我補充說明一下,strtok會去修改來源字串, 05/03 15:28
→ freesamael:而常數字串無法被修改,所以就爛掉了。 05/03 15:28
→ apiod:thanks 05/03 16:04