Hi, the code below has problems displaying the inputs that I want. I'm not sure whether the complier is able to read my inputs or unable to display them.
EDIT: I realised that if I do this, the console doesn't display my last input. (I mean it displays 3 out of the 4 inputs I key in).
1 2 3 4 5 6 7 8 9 10 11 12 13 14
std::cout << "You've " << m << " number of strings.\nEnter the strings, in sequence, below:\n";
char ** n = newchar *[m];
for (int i = 0; i < m; i++)
{
n[i] = newchar [99];
std::cin.getline (n[i],99);
std::cout << n[i] << "\n"; //edited line
}
std::cout << "Your longest string is: " << maxn (n[99], m);
for (int i = 0; i < m; i++)
delete [] n[m];
delete [] n;
The other function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
template <> char * maxn (char * a[], int b)
{
int maxlen;
maxlen = getcharcount (a[0]);
char * p = a[0];
for (int i = 0; i < b; i++)
{
int len = getcharcount(a[i]);
if (maxlen < len)
{
maxlen = len;
p = a[i];
}
}
return p;
}
I'm not sure where went wrong, but after entering the strings, the complier just terminates without any errors or warnings.
By the way, is it okay if I return p? I know that returning temporary addresses is bad and it will result in errors. However, the complier I'm using doesn't display any error messages.
Thanks!
Yea, this question is related to the previous question I asked. Seems like solving one creates another one :\