I need to find the sentence from the file, which had the greatest number of characters, but I can't find the index for start the sentences( I know that my problem is in this part
(if ((n == '?')||(n == '!')||(n == '.')) {
newIndex = index;
}
But I don't know how to improve it. The part below is the rest of my code.
using namespace std;
int main()
{
int newIndex = 0;
int startSentensec = 0;
int endSentenses = 0;
int index = -1;
int count = 0;
const string wayToFile = " " ;
int total = 0;
char n;
vector<char>MyVector;
ifstream file(wayToFile);
while (!file.eof())
{
file >> n;
if (file.eof()) break;
index += 1;
MyVector.push_back(n);
cout << n << " ";
//123
if ((n == '0' ) ||(n == '1' ) ||(n == '2' ) ||(n == '3' ) ||(n == '4' ) ||(n == '5' ) ||(n == '6' ) ||(n == '7' ) ||(n == '8' ) ||(n == '9' )) {
count += 1;
}
///456
if ((n == '?')||(n == '!')||(n == '.')) {
newIndex = index;
if (count >= total){
total = count;
endSentenses = index;
startSentensec = newIndex ;
count = 0;
}
}
}
file.close();
cout << endl<< "Sentences with the greatest number of digits :";
for (int i = (startSentensec); i <= endSentenses; i++){
cout << MyVector[i];
}
cout << endl;
cout << total << endl;
}