Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include "Edit.h"
  2. using namespace std;
  3.  
  4.  
  5. Edit::Edit(): text(NULL), hc(GetStdHandle(STD_OUTPUT_HANDLE))
  6. {
  7. c.X = 0;
  8. c.Y = 0;
  9. }
  10.  
  11.  
  12. Edit::~Edit()
  13. {
  14. }
  15.  
  16. void Edit::setPosition(int x, int y)
  17. {
  18. c.X = x;
  19. c.Y = y;
  20. SetConsoleCursorPosition(hc,c);
  21. }
  22.  
  23. void Edit::setLength(int L)
  24. {
  25. delete[] text;
  26. this->text = new char[L+1];
  27. text[L] = '\0';
  28. Length = L;
  29. }
  30.  
  31. void Edit::setText(const char* text)
  32. {
  33.  
  34. if (strlen(this->text) > 0)
  35. {
  36. //setLength(strlen(this->text));
  37. for (int i = 0; i < strlen(this->text); i++)
  38. this->text[i] = text[i];
  39.  
  40. this->text[strlen(text)] = '\0'; //Ustawianie spacji na ostatnim miejscu tablicy
  41. }
  42.  
  43. else
  44. {
  45. this->text = new char[strlen(text) + 1]; //Alokowanie pamieci na wprowadzony text
  46. for (int i = 0; i < strlen(text); i++)
  47. this->text[i] = text[i];
  48.  
  49. this->text[strlen(text)] = '\0'; //Ustawianie spacji na ostatnim miejscu tablicy
  50. }
  51.  
  52. }
  53.  
  54. void Edit::display()
  55. {
  56. for (int i = 0; i < Length; i++)
  57. {
  58. if(text[i]!='\0')
  59.  
  60. else
  61.  
  62. }
  63. }
  64.  
  65. char *Edit::getText()
  66. {
  67. return text;
  68. }
  69.  
  70. void Edit::userText()
  71. {
  72.  
  73. char charly;
  74. int length = strlen(text);
  75. cout << "length" << length<<endl;
  76. int index = 0;
  77. bool bolek = 1;
  78. /*
  79. for (int i = 0; i < (length + 1); i++)
  80. {
  81. if (text[i] != '\0')
  82. {
  83. index++;
  84. cout << "index" << index << endl;
  85. }
  86. else if(text[i]=='\0' && index==0)
  87. index = 0;
  88. }*/
  89.  
  90.  
  91. if (length > 0)
  92. {
  93.  
  94. while (bolek)
  95. {
  96. charly =_getch();
  97.  
  98.  
  99.  
  100.  
  101. }
  102. this->text[length] = '\0'; //Ustawianie spacji na ostatnim miejscu tablicy
  103. }
  104.  
  105. else
  106. {
  107. cout << "0";
  108. }
  109. }
  110. /*
  111. std::ostream& operator<<(std::ostream o, const Edit eddy)
  112. {
  113. // TODO: tu wstawić instrukcję return
  114. }
  115. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement