Guest User

Untitled

a guest
Nov 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. string str;
  11. int *statistic = new int [0];
  12.  
  13. char slovo[15];
  14. for(int i = 0; i<15; i++){
  15. slovo[i] = ' ';
  16. }
  17.  
  18. int count_word = 0;
  19. char** words = new char* [0];
  20. for (int i = 0; i<count_word; i++){
  21. words[i] = new char[15];
  22. }
  23.  
  24. ifstream text("text.txt");
  25.  
  26. while (getline(text, str, ' ')){
  27.  
  28. cout<<endl<<endl;
  29. for (int i = 0; i<str.size(); i++){
  30. slovo[i] = str[i];
  31. }
  32.  
  33. cout<<"generate new_words "<<count_word<<endl;
  34. char** new_words = new char*[count_word];
  35. for (int i = 0; i<count_word; i++){
  36. new_words[i] = new char[15];
  37. }
  38. for (int i = 0; i<count_word; i++){
  39. for (int j = 0; j<15; j++){
  40. new_words[i][j] = words[i][j];
  41. }
  42. }
  43.  
  44.  
  45. cout<<"delete words "<<count_word<<endl;
  46. for (int i = 0; i<count_word; i++){
  47. delete words[i];
  48. }
  49. delete [] words;
  50.  
  51.  
  52. count_word += 1;
  53.  
  54. cout<<"generate words "<<count_word<<endl;
  55. char** words = new char* [count_word];
  56. for (int i = 0; i<count_word; i++){
  57. words[i] = new char[15];
  58. }
  59. for (int i = 0; i<count_word-1; i++){
  60. for (int j = 0; j<15; j++){
  61. words[i][j] = new_words[i][j];
  62. }
  63. }
  64.  
  65.  
  66. cout<<"delete new_words "<<count_word-1<<endl;
  67. for (int i = 0; i<count_word-1; i++){
  68. delete new_words[i];
  69. }
  70. delete [] new_words;
  71.  
  72.  
  73. for (int i = 0; i<15; i++){
  74. words[count_word-1][i] = slovo[i];
  75. }
  76.  
  77. //вывод массива в цикле
  78. for (int i = 0; i<count_word; i++){
  79. for (int j = 0; j<15; j++){
  80. cout<<words[i][j];
  81. }
  82. cout<<endl;
  83. }
  84. cout<<endl<<endl;
  85.  
  86. }
  87. text.close();
  88.  
  89.  
  90. /* for (int i = 0; i<1; i++){
  91. for (int j = 0; j<15; j++){
  92. cout<<words[i][j];
  93. }
  94. cout<<endl;
  95. }*/
  96.  
  97.  
  98. return 0;
  99. }
Add Comment
Please, Sign In to add comment