I created an array with the maximum dimension for text input. Now, I want to remove the remaining unnecessary part in order to free the memory. I am not allowed to use std::string, I need to use char[] arrays only.
Also, if you know better way how to use only char and allocate dynamic memory for text input, please help me. I do not know how many characters the user will enter
#include <iostream>
using namespace std;
int main()
{
char *text = new char[256];
cout << "Input text: ";
cin.getline(text,256,'\n');
while (cin.fail())
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max, '\n');
cout << "Input text: ";
cin.getline(text,256,'\n'); //need to delete part after '\n';
}
return 0;
}
C?