Advertisement
KristianIvanov00

Untitled

Jan 8th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int MYstrlen(char* str)
  6. {
  7. int counter = 0;
  8. while (*str != '\0')
  9. {
  10. counter++;
  11. str++;
  12. }
  13. return counter;
  14. }
  15.  
  16. int strCompare(char* first, char* second)
  17. {
  18. if (MYstrlen(first) != MYstrlen(second))
  19. {
  20. return MYstrlen(first) - MYstrlen(second);
  21. }
  22. int counter = 0;
  23. while (*(first + counter) != '\0')
  24. {
  25. if (*(first + counter) != *(second + counter))
  26. {
  27. return -1;
  28. }
  29. }
  30. return 0;
  31. }
  32. char** splitSentence(char* sentence)
  33. {
  34. int numbOfWords = 1;
  35. int sentSize = MYstrlen(sentence);
  36. for (int i = 0; i < sentSize; i++)
  37. {
  38. if (sentence[i] == ' ')
  39. {
  40. numbOfWords++;
  41. }
  42. }
  43. char** returnValue = new char* [numbOfWords];
  44. for (int i = 0; i < numbOfWords; i++)
  45. {
  46. int sizeofword = 0;
  47. while (sentence[i] != ' ')
  48. {
  49. i++;
  50. sizeofword++;
  51. }
  52. returnValue[i] = new char[sizeofword];
  53. //copy
  54. }
  55. }
  56. void printWords(char* sentence, char ** dictionary)
  57. {
  58.  
  59. }
  60.  
  61. int main()
  62. {
  63. char* sentence;
  64. char** dictionary;
  65. int sentSize, numbOfWords, sizeofWords;
  66. cin >> sentSize >> numbOfWords >> sizeofWords;
  67.  
  68. sentence = new char(sentSize);
  69. if (!sentence)
  70. {
  71. return 0;
  72. }
  73. dictionary = new char* [numbOfWords];
  74. if (!dictionary)
  75. {
  76. return 0;
  77. }
  78. for (int i = 0; i < numbOfWords; i++)
  79. {
  80. dictionary[i] = new char[sizeofWords];
  81. if (!dictionary[i])
  82. {
  83. return 0;
  84. }
  85. }
  86. cin.get();
  87. cin.getline(sentence, sentSize);
  88. cout << MYstrlen(sentence);
  89.  
  90. printWords(sentence, dictionary);
  91.  
  92. for (int i = 0; i < numbOfWords; i++)
  93. {
  94. delete[] dictionary[i];
  95. }
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement