Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 14 / task7.cpp
diff options
context:
space:
mode:
Commita2c2185b99f57d9fdd58f6a2e8389f6c67d82f96 (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2021-01-09 13:44:59 -0500
Committer
 GitHub <noreply@github.com>
2021-01-09 13:44:59 -0500
Filescc5839a9295f7ebc0cdc14e75f90ea90fe2f9d68 /Sem. 14/task7.cpp
Introduction_to_programming_FMI-a2c2185b99f57d9fdd58f6a2e8389f6c67d82f96.tar
Introduction_to_programming_FMI-a2c2185b99f57d9fdd58f6a2e8389f6c67d82f96.tar.gz
Introduction_to_programming_FMI-a2c2185b99f57d9fdd58f6a2e8389f6c67d82f96.zip
Parentf66ac6bdd224ac513a5155bce511ce95af202388 (diff)
Create task7.cpp
1 files changed, 63 insertions, 0 deletions
-rw-r--r--Sem. 14/task7.cpp63
diff --git a/Sem. 14/task7.cpp b/Sem. 14/task7.cpp
new file mode 100644
index 0000000..fce9e8b
--- /dev/null
+++ b/Sem. 14/task7.cpp
@@ -0,0 +1,63 @@
+#include <iostream>
+#include <cstring>
+using namespace std;
+
+const int MAXLEN = 1024;
+
+
+int fillWords(const char* str, char words[MAXLEN][MAXLEN])
+{
+ int len = strlen(str);
+
+ int currentWordCursorInMatrix = 0;
+ int count = 0 ;
+
+ for(int i = 0; i < len; i++)
+ {
+ if(str[i] == ' ')
+ {
+ if(currentWordCursorInMatrix != 0)
+ {
+ words[count][currentWordCursorInMatrix] = '\0';
+ count++;
+ currentWordCursorInMatrix = 0;
+ }
+ }
+ else
+ {
+ words[count][currentWordCursorInMatrix] = str[i];
+ currentWordCursorInMatrix++;
+ }
+ }
+
+ return count;
+
+}
+
+void createReversedSentence(char words[MAXLEN][MAXLEN], int wordsCount, char* newSentence)
+{
+
+ for (int j = wordsCount - 1; j >= 0 ; j--)
+ {
+ strcat(newSentence, words[j]);
+ strcat(newSentence, " ");
+ }
+}
+int main()
+{
+ const char* str = "How are you friends. I am fine!";
+
+ char words[MAXLEN][MAXLEN];
+
+ int wordsCount = fillWords(str, words);
+
+ char* newSentense = new char[strlen(str)];
+
+ createReversedSentence(words, wordsCount, newSentense);
+
+ cout << newSentense << endl;
+
+ delete[] newSentense;
+
+ return 0;
+}