EDIT
I am currently studying the comments written down for me below
A function that get a structure that contains a pointer to a array of sentences, and the amount of sentences. and returns a structure that contains a pointer to an array of words, and the amount of words (the sentences are split into words).
In the current function, a primary loop that through a sentence, and a secondary loop that through the one sentence.
During the loop, each character of the sentence is copied to a new word, until space. and move to the next word after the space.
The problem is, writing to the pointer of the current word overwrites the previous word, rather than copied to its right place. You can notice that in later words, there is a basis of the previous words. (The program "on the fly" after the fourth word)
Expression:
Sentences spilt(Sentences sentence) {
Sentences words = {nullptr, 0};
int basic_size = 5;
int arr_size = 5;
words._data = new(nothrow) char *[basic_size];
for(int i = 0; i < sentence._num_of_sentences; i++) { // iterate though serntes
for (int sent_inter = 0, words_inter = 0; sent_inter < strlen(sentence._data[i]); sent_inter++) { // iterate though words
//alloc amount of words
if(words._num_of_sentences == basic_size)
//func of alloc_sen
//alloc len of word
if(strlen(words._data[words._num_of_sentences]) == arr_size)
//func of alloc_word
if(sentence._data[i][sent_inter] == '\n')
break;
//next new word
if (sentence._data[i][sent_inter] == ' ') {
words._data[words._num_of_sentences][words_inter] = '\0';//endline
++words._num_of_sentences;
words_inter = 0;
continue;
}
//copy correct character to correct word
words._data[words._num_of_sentences][words_inter++] = sentence._data[i][sent_inter];
//cout << words._data[words._num_of_sentences] << endl;
}
++words._num_of_sentences;
}
return words;
}
Temp result:
Input:
qwe rty uio
asd fgh jkl
zxc vbn
output:
q$g☻
qwg☻
->qwe☻
r↓♦️
rt♦️
->rty☺️
uwe
uie
->uio
aty
asy
->asd
now break