When I try to copy arrays into a jagged array. My goal is to take an array of type char, separate the "words" into separate arrays (I use an already working function for it) and want to put them into an array.
static char[][] split_string(char[] str)
{
int length = count_words(str);
char[][] sentence = new char[length][];
int start = 0;
int end = 0;
int word = 0;
int i = -1;
while (i != str.Length)
{
i++;
if (str[i]==' ')
{
end = i-1;
char[] aux_array = substring(str, start, end);
//issue
aux_array.CopyTo(sentence[word], 0);
//alternative (not working either)
/*
for(int j=0; j<aux_array.Length;j++)
{
sentence[word][j] = aux_array[j];
}
*/
while (str[i]==' ')
{
i++;
}
word++;
start = i;
}
}
return sentence;
}
For information,
substring if of the form: substring(array, int, int) -> array
count_word is of the form: count_word(array) -> int