I used strtok
to split a string.
[UPDATE] I used your comments and answer for the new version below, but didn't work 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;
};
The printf("tmp[idx] ...
is correctly printed.
But in my main after I run the method:
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);
the array split_url
is empty.
Compiler and gdb are fine.
Does someone have an idea?