avr39-ripe

dyn2DStringArr

Sep 26th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     char** text = new char*[100]{};
  6.     char* buf = new char[300]{};
  7.    
  8.     int textPos = 0;
  9.     char addMore = 'Y';
  10.  
  11.     while ((addMore == 'Y' or addMore == 'y') and textPos < 100)
  12.     {
  13.         std::cin.getline(buf, 300);
  14.         int len = strlen(buf) + 1;
  15.         text[textPos] = new char[len];
  16.         strcpy_s(text[textPos], len, buf);
  17.         textPos++;
  18.        
  19.         std::cout << "\nAdd another line? [Y/y to add]";
  20.         std::cin >> addMore;
  21.         std::cin.ignore();
  22.     }
  23.    
  24.     std::cout << "Here is yor lines \n";
  25.  
  26.     for (textPos = 0; text[textPos]; textPos++)
  27.     {
  28.         std::cout << text[textPos] << '\n';
  29.     }
  30.  
  31.     for (textPos = 0; text[textPos]; textPos++)
  32.     {
  33.         delete[] text[textPos];
  34.     }
  35.     delete[] text;
  36.     delete[] buf;
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment