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* [maxLines] {} };
- 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);
- int len = strlen(buf) + 1;
- memoryUsed += len;
- text[textPos] = new char[len];
- strcpy_s(text[textPos], len, buf);
- ++textPos;
- std::cout << "\nAdd another line? [Y/y to add]";
- std::cin >> addMore;
- std::cin.ignore(32768, '\n');
- }
- std::cout << "Here is yor lines \n";
- for (textPos = 0; text[textPos]; ++textPos)
- {
- std::cout << text[textPos] << '\n';
- }
- std::cout << "Memory used to store this text: " << memoryUsed << '\n';
- for (textPos = 0; text[textPos]; ++textPos)
- {
- delete[] text[textPos];
- }
- delete[] text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement