Trying to get number of sentences in a file

closed account (98RMoG1T)
Write your question here.
Hello. i am doing a project. basically the program is where the user will input the path, and from there it will read how many sentences the file has. but i can't get how many sentences in the file. i only manage to get all the lines. can anyone please help if i am missing anything?

[code]
#include <iostream>
#include <fstream>
using namespace std;

string text;
string filename;


void enter_path(){

getline(cin, filename );
fstream file( filename.c_str() );
if (!file)
{
cout << "Could not open the file.\n";

}
else
{
string line;
int count = 30;
while (getline (file, line))
{
cout << line << '\n';
count--;

}
file.close();
}



}
int count_sentence(string text){
int number_sentences = 0;
for(int i=0; i<text.length();i++)
if(text[i] == '.')
number_sentences++;
return number_sentences;

}

int main(){


cout<<"Enter your path: \n";

enter_path();

int count_sentence(string);
getline(cin, text);
cout<<"No of sentences are: "<<count_sentence(text)<<endl;


system ("pause");
return 0;
}
Number of periods (full stops) is the number of sentences.
Topic archived. No new replies allowed.