嗨,我编写了这段测试代码,在第三次迭代时产生段错误...使用调试器我看到了 tokens[count] 的值,它是正确的,但在最后一次迭代中出现了段错误, str_split 使用 ; 分割字符串作为除数(有效) 有人可以帮忙吗?
sportello[0].elenco_ris[0]=strdup("string;of;test");
tokens=str_split(sportello[0].elenco_ris[0],';');
int p=0;
int count=0;
int lungh=strlen("");
while(p!=-1){
lungh=strlen(tokens[count]);
if(lungh!=0){
printf("\nprinto: %s",tokens[count]);
count++;
}
else p=-1;
}
打印:字符串 打印: 的
运行完成;分段故障;实时:0ms;用户:0ms;系统:0ms
最佳答案
好吧,我解决了……问题就是我所想的……感谢 @Joachim Pileborg 的评论,我已经尝试过这个(NULL)……所以谢谢大家
`int p=0;
int count=0;
while(p!=-1){
if (tokens[count] != NULL){
printf("\nprinto: %s",tokens[count]);
count++;
}
else p=-1;
}`
关于c - 在字符串数组上使用指针的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27928166/