I will try to formulate the condition of the problem: the given string str1: "A roza upala, na lapu + Azora!" divided into individual words using the strcspn and strspn functions, the first one counts the number of elements of the string str1 not included in the string str2: ",.!? + -" (delimiter string) until elements from str2 appear in str1. I used the second function to determine the element on which the pointer stands, the separator or not.
сhar str1[] = "++A roza upala, na lapu Azora.! "; char str2[] = " +-.,!?"; char *word = new char [15]; char **ptrArray = new char*[20]; int k, n, j, i = 0; char *pstr1 = str1 , *pfun; while(pstr1 < str1 + strlen(str1)) { n = strspn(pstr1,str2); if (n!= 0) pstr1++; else { k = strcspn(pstr1, str2); pfun = pstr1 + k; //заполнение указателя j = 0; for (char *pout = pstr1; pout < pfun; pout++) { *(word+j) = *pout; j++; } *(word+j) = ' '; //заполнение массива указателей указателями на слова ptrArray[i] = word; delete[]word; // очистка pstr1 = pfun + 1; i++; // кол-во указателей(слов) + 1 } } //cases for output if (i < 7) { for (int m = i-1; m >= 0; m--) cout << ptrArray[m]; } else { for (int m = 0; m < i; m += 2) cout << ptrArray[m]; } //cleaning all up for (int ii = 0; ii < i; ii++) delete[] ptrArray[ii]; delete[] ptrArray; It is necessary to form a line of words separated by spaces in the reverse order, if there are less than seven words, otherwise every second word. And display on the screen. In my solution, I used dynamic selection, first for a separate word (string), and then for an array of strings. The WORD pointer is needed to allocate memory for each new word (string). Perhaps the problem is here:
for (char *pout = pstr1; pout < pfun; pout++) { *(word+j) = *pout; j++; } *(word+j) = ' '; //заполнение массива указателей указателями на слова ptrArray[i] = word; At the end of the program I try to organize the output I need through pointers to pointers to words (lines).
if (i < 7) { for (int m = i-1; m >= 0; m--) cout << ptrArray[m]; } else { for (int m = 0; m < i; m += 2) cout << ptrArray[m]; } Help, who can! (I will be grateful)