Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 14 / task7.cpp
diff options
context:
space:
mode:
Commit6d358e061de78de8f1e7d43ce2495ae468b86ea5 (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2021-01-09 14:00:14 -0500
Committer
 GitHub <noreply@github.com>
2021-01-09 14:00:14 -0500
Files003efc20c48bf6b12fe04dfc97d844e179d11eff /Sem. 14/task7.cpp
Introduction_to_programming_FMI-6d358e061de78de8f1e7d43ce2495ae468b86ea5.tar
Introduction_to_programming_FMI-6d358e061de78de8f1e7d43ce2495ae468b86ea5.tar.gz
Introduction_to_programming_FMI-6d358e061de78de8f1e7d43ce2495ae468b86ea5.zip
Parent1b83a3de9ed98c29919bf55ebecba4416e6e09ae (diff)
Update task7.cpp
1 files changed, 7 insertions, 6 deletions
-rw-r--r--Sem. 14/task7.cpp13
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()