I am trying to implement a split funtion, which receives an array of chars and a delimiter that will decide what chars go to each array in the split array.
I have a problem with strcat and memset, can somone explain my mistakes to me?
char** split(const char* str, char delimiter)
{
int ch=0;
int word=0;
const char * zero="\0";
unsigned int size=num_items(str,delimiter);
/* get the size of split[][] */
char** split= calloc(size+1,sizeof(char*));
for(int i=0; i<strlen(str); i++)
{
if(ch==0)
{
memset(split[word],'\0',1);
/* set the first value to '\0' */
ch++;
}
if(str[i]!=delimiter)
{
/* adding char by char to the split */
strcat(split[word],&str[i]);
ch++;
}else{
ch=0;
word++;
}
}
return split;
}