Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <signal.h>
  5. #include <iostream>
  6. #include <memory>
  7. #include <math.h>
  8. #include <ctime>
  9. #include <vector>
  10. using namespace std;
  11. void reaction_on_signal(int);
  12. char* generate_str(int len);
  13. void reaction_on_stop(int);
  14.  
  15. int main()
  16. {
  17.     srand(time(0));
  18.     std::vector<char*> mem_p;
  19.     signal(SIGINT,reaction_on_signal);
  20.     signal(SIGTSTP,reaction_on_stop);
  21.     int length = 80;
  22.  
  23.     //length = atoi(getenv("COLUMNS"));
  24.    // if(length)
  25.     std::cout << "Terminal str length:" << length << std::endl;
  26.     try
  27.     {
  28.         while(true)
  29.         {
  30.         char *tmp = generate_str(length);
  31.         std::cout << tmp << std::endl;
  32.        mem_p.push_back(tmp);
  33.         }
  34.     }
  35.     catch(std::bad_alloc)
  36.     {
  37.         std::cout << "mem full" << std::endl;
  38.     }
  39.  
  40.     return 0;
  41. }
  42.  
  43. void reaction_on_signal(int)
  44. {
  45.     ;
  46. }
  47.  
  48. void reaction_on_stop(int)
  49. {
  50.     exit(0);
  51. }
  52.  
  53. char* generate_str(int len)
  54. {
  55.     char* str = new char[len];
  56.     for(int i=0;i < len; ++i)
  57.     {
  58.         str[i] = (char) (rand() % 126 + 35);
  59.     }
  60.     str[len - 1] = '\0';
  61.     return str;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement