Guest User

Untitled

a guest
Jul 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include "History.h"
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5.  
  6. History::History()
  7. {
  8. hist = {0};
  9. index = 0;
  10. r_index = 0;
  11. }
  12.  
  13. History::~History()
  14. {
  15. for (int i = 0; i < 20; i++)
  16. {
  17. if (hist[i] != 0)
  18. {
  19. delete[] (hist[i]);
  20. }
  21. }
  22. }
  23.  
  24. void History::addEntry(char* str)
  25. {
  26. if (hist[index] != NULL)
  27. {
  28. delete[] (hist[index]);
  29. }
  30.  
  31. hist[index] = new char[65];
  32. strcpy(hist[index], str);
  33.  
  34. index = (index + 1) % 20;
  35. }
  36.  
  37. void History::printEntry()
  38. {
  39. printf( "%s", hist[r_index] );
  40. fflush(stdout);
  41. }
  42.  
  43. void History::printAll()
  44. {
  45. r_index = index;
  46. if (hist[0] == NULL)
  47. {
  48. }
  49. else if (hist[(index + 1) % 20] == NULL)
  50. {
  51. r_index = 0;
  52. while(r_index < index)
  53. {
  54. printEntry();
  55. printf("%c", '\n');
  56. fflush(stdout);
  57. r_index++;
  58. }
  59. }
  60. else
  61. {
  62. for(int i = 0; i < 20; i++)
  63. {
  64. printEntry();
  65. r_index = (r_index - 1) % 20;
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment