有人能解释一下为什么我在以下示例中会遇到分段错误吗?
#include <stdio.h>
#include <string.h>
int main(void) {
char *hello = "Hello World, Let me live.";
char *tokens[50];
strtok_r(hello, " ,", tokens);
int i = 0;
while(i < 5) {
printf("%s\n", tokens[i++]);
}
}
char *ptr = Hello;
大写H?另外,Alok的回答说第一次调用需要 "标记化" 第一个参数,然后后续调用它需要为NULL,但是你的示例似乎只在while循环中调用了一种方式?顺便感谢你提供的代码 - SSH Thishello
指向char hello[]...
。 - MrHIDEn