Hello, I was working on a question and I seemed to be unable to get this part working properly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
else if (m == 'c')
{
std::cout << "Enter the number of sentences used: ";
int e;
std::cin >> e;
std::cin.clear();
std::cin.ignore(1000, '\n');
std::cout << "You've " << e << " number of sentences required to be filled.\n";
char * f[e];
for (int i = 0; i < e; i++)
{
std::cout << "Enter your " << i << " sentence: ";
std::cin.getline (f[i], 99);
};
char * g = maxn (f, e);
std::cout << "Your longest sentence is: " << g;
}
|
What I got instead was this:
Enter the number of sentences used: 4
You've 4 number of sentences required to be filled.
Enter your 0 sentence: Orange Juice
Exit code: 0 (normal program termination)
I know I can use string instead of a c-string, but the exercise I'm doing only permits c-string. Is there any way I can solve this problem? Thanks!
Edit: I tried using ignore and clear below the getline function but I still got a cut-off message from the console.
Last edited on
f is an array of pointers but you have forgot to initialize the pointers. You need to make them point somewhere.
Do you have any idea how to I go about solving this problem?
If I'd given the strings beforehand, the program works. But getting user inputs seem to left me stuck at this portion.
EDIT: I found out how to resolve this problem. Thanks!
Last edited on