diff options
1 files changed, 7 insertions, 6 deletions
| -rw-r--r-- | Sem. 14/task7.cpp | 13 |
diff --git a/Sem. 14/task7.cpp b/Sem. 14/task7.cpp index fce9e8b..abe8458 100644 --- a/Sem. 14/task7.cpp +++ b/Sem. 14/task7.cpp @@ -4,19 +4,19 @@ using namespace std; const int MAXLEN = 1024; - +//creates a matrix of the words in the sentence. int fillWords(const char* str, char words[MAXLEN][MAXLEN]) { int len = strlen(str); int currentWordCursorInMatrix = 0; - int count = 0 ; + int count = 0 ; //also the index of the row in the matrix. for(int i = 0; i < len; i++) { - if(str[i] == ' ') + if(str[i] == ' ') // the current word ends here. { - if(currentWordCursorInMatrix != 0) + if(currentWordCursorInMatrix != 0) // check if we have writen at least one symbol in the current word. { words[count][currentWordCursorInMatrix] = '\0'; count++; @@ -25,7 +25,7 @@ int fillWords(const char* str, char words[MAXLEN][MAXLEN]) } else { - words[count][currentWordCursorInMatrix] = str[i]; + words[count][currentWordCursorInMatrix] = str[i]; // we write the symbol in the current word. currentWordCursorInMatrix++; } } @@ -40,7 +40,8 @@ void createReversedSentence(char words[MAXLEN][MAXLEN], int wordsCount, char* n for (int j = wordsCount - 1; j >= 0 ; j--) { strcat(newSentence, words[j]); - strcat(newSentence, " "); + if(j != 0) + strcat(newSentence, " "); //the space between the words } } int main() |
