Guest User

Untitled

a guest
Dec 12th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. void push_history(char **args)
  2. {
  3.     int args_length = 0;
  4.     for(int i = 0; args[i] != NULL; i++)
  5.         args_length++;
  6.  
  7.     char ** hard_copy = new char*[args_length];
  8.  
  9.     for(int i = 0; i < args_length; i++)
  10.         hard_copy[i] = args[i];
  11.    
  12.  
  13.     vector_length++;
  14.     hist.push_back(hard_copy);
  15. }
  16.  
  17.  
  18. //print history
  19. void printHistory()
  20. {
  21.     int count = 0;
  22.     string str_cat = "";
  23.    
  24.     if(vector_length <= 10)
  25.     {
  26.         for(int i = 0; i < vector_length; i++)
  27.         {
  28.             str_cat = "";
  29.             for(int ii = 0; hist[i][ii] != NULL; ii++)
  30.             {
  31.                 str_cat += hist[i][ii];
  32.                 str_cat += " ";
  33.             }
  34.             cout << (count+1) << "  " << str_cat <<  endl;
  35.             count++;
  36.         }
  37.     }
  38.    
  39.     //more than 10 commands in history
  40.     else
  41.     {
  42.         for(int i = vector_length - 10; i < vector_length; i++)
  43.         {
  44.             str_cat = "";
  45.             for(int ii = 0; hist[i][ii] != NULL; ii++)
  46.             {
  47.                 str_cat += hist[i][ii];
  48.                 str_cat += " ";
  49.             }
  50.             cout << (count+1) << "  " << str_cat <<  endl;
  51.             count++;
  52.         }
  53.     }
  54. }
Add Comment
Please, Sign In to add comment