我曾经strtok
拆分一个字符串。
[更新]我在下面的新版本中使用了您的评论和答案,但在 atm 中不起作用
int Crawl :: splitUrl(char ***tmp, int max_length, char *url)
{
int idx=0;
char * p;
int i;
p = strtok (url,"/");
while (p != NULL && idx < max_length)
{
for (i=0;i<maxUrlSize-1 && p[i] != '\0';i++)
(*tmp)[idx][i] = p[i];
for ( ; i< maxUrlSize-1;i++)
(*tmp)[idx][i] = '\0';
printf("tmp[idx[%d]] %s\n",idx,(*tmp)[idx]);
idx++;
p = strtok (NULL, "/");
}
return idx;
};
printf("tmp[idx] ...
打印正确。
但是在我运行该方法之后,我主要是:
split_url = new char * [ maxUrlSplits ];
for (int k=0;k<maxUrlSplits;k++)
split_url[k] = new char [maxUrlSize];
arr_size = crawl->splitUrl(&split_url,maxUrlSplits,url);
数组split_url
为空。
编译器和 gdb 都很好。
有人有想法吗?