char *pointers_on_words[20]; char str[]= "First Second Third"; string_split(str,pointers_on_words); int string_split(char* string,char * array_results){ static int word_count; if( *string == '\0'){ int k= word_count; word_count =0; return k+1; }//конец строки if( *(string-1) == '\0'){// если предыдущий символ \0 - значит началось новое слово *array_results = string;//запись адреса нового слова array_results++; word_count++; } if(*string == ' '){//заменяем пробелы на \0 *string = '\0'; } return string_split(string+1,array_results); } 

The result of this function should be a string broken into words separated by a \ 0 -character. And an array of pointers array_results, in which there should be pointers to the beginning of these very words.

But an error occurs when writing the address to the array of pointers.

3 answers 3

You have declared the second parameter as char *

 int string_split(char* string,char * array_results){ ^^^^^^^^^^^^^^^^^^^^ 

so at least in this sentence

 *array_results = string; 

a compilation error should occur since the left assignment operand is of type char , and the right operand is of type char * .

  • But array_results is after all an array of pointers, how else can it write an address? - Hardc0re 5:46
  • @ Hardc0re you declared the parameter not as an array of pointers, but as a pointer. - Vlad from Moscow

The second parameter of the function should be described like this:

 char * array_results[] 

Accordingly, the code under the condition rewrite so:

 array_results[word_count] = string; word_count++; 

What, in fact, will happen when a recursive function call with a static variable, I can not imagine ... Why is this necessary? After all, everything is solved by the method of linear viewing the line in one pass.

    This is not a mistake, but a warning. You need to do a type conversion

    • Where is the warning ?? - Qwertiy