Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- const int maxLines{ 100 };
- const int maxLen{ 200 };
- //char** text{ new char* [maxLen] {} };
- //char* buf{ new char[maxLen] };
- char* text[maxLen]{};
- char buf[maxLen]{};
- int textPos{ 0 };
- char addMore{ 'y' };
- int memoryUsed{ 0 };
- while ( (addMore == 'y') or (addMore == 'Y') and textPos < maxLines )
- {
- std::cout << textPos << '.';
- std::cin.getline(buf, maxLen - 1);
- int len{ (int)strlen(buf) + 1 };
- memoryUsed += len;
- *(text + textPos) = new char[len];
- strcpy_s(*(text + textPos), len, buf);
- ++textPos;
- std::cout << "Add another line? [Y/y to add]";
- std::cin >> addMore;
- std::cin.ignore(32767, '\n');
- }
- std::cout << "Here is your text:\n";
- for (textPos = 0; *(text + textPos) and textPos < maxLines; ++textPos)
- {
- std::cout << *(text + textPos) << '\n';
- }
- std::cout << "Memory used to store this text: " << memoryUsed << '\n';
- for (textPos = 0; *(text + textPos) and textPos < maxLines; ++textPos)
- {
- delete[] *(text + textPos);
- }
- //delete[] text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement