void word_print(char * array,int begin){ if(begin != 0 || *(array+(begin-1)) != ' '){ while( *(array+begin)!=' ' && *(array+begin)!='.' && *(array+begin)!=',' && begin != 0){ begin= begin - 1; } } while( *(array+begin)!=' ' || *(array+begin)!='.' || *(array+begin)!=',' || *(array+begin)!='\0'){ printf("%c",*(array+begin++)); } } 

At the input of the function comes a string and an integer value that indicates the word to be printed.

The problem is that the second cycle with word_print("1234 56", 7); the arguments are infinite, although the while condition should work

  • Do you want to print the word from the end of the line? That is, the analysis of the line you are going from right to left * - Vlad from Moscow
  • @VladfromMoscow, no. we get the index of the letter that is in the word we need. If this is not the beginning of the line, and not the beginning of the word, then we decrement the index number until it is a space, the beginning of the line or., - Hardc0re
  • Well, if you reduce the position, this means that you want to display words from the end of the sentence, that is, the movement goes from right to left. If you print from the beginning of the line, then the position, if it hits the space, should move to the right. - Vlad from Moscow
  • Yes, I already understood, thanks. - Hardc0re
  • "The value that indicates the name to be printed" is interesting, but it seemed to me that we are talking about the ordinal number of the word in the line? - PinkTux

1 answer 1

Record the cycle condition correctly

 while( *(array+begin)!=' ' && *(array+begin)!='.' && *(array+begin)!=',' && *(array+begin)!='\0'){ printf("%c",*(array+begin++)); 

True before this loop at the end of the if clause, add

 ++begin;