I have an array of 20 strings with a maximum of 81 characters that will be populated by the user, how do I go about removing the excess null characters at the end should the users input be > 81 characters?
I've tried to search for solutions to this, but most seem to require me to know how many characters the user has input into the string before the program is run.
int main()
{
string strings[20];
cout << "Enter up to 20 strings, press enter when done: ";
input(strings);
for (int i = 0; i < 20; i++)
{
if (strings[i] == "\0")
break;
else
{
strings[i].resize(81);
cout << "Here is string" << i << ": " << endl << strings[i] << endl;
menu(strings[i]);
}
}
void input(string strings[])
{
for (int i = 0; i < 20; i++)
{
getline(cin, strings[i]);
if (strings[i] == "\0")
break;
}
}