Help with sentence counting

I have to write a program that tabulates the characters in a text file.
I need help writing the code that will perform a sentence count.

It states that a sentence is defined as the number of occurrences of the period in the file which is followed by at least two blanks.

i.e.

How are you. Today is a nice weather.

Would give out sentence count of 2.

This is the sample code he gave us.. to do a sentence count with the sentence being defined as a period and a newline character.
1
2
3
4
5
6
7
8
9
10
11
   ifstream input( "testfile.txt");
   bool havepunct = false;
   sentences = 0;
   
    if (c == '.') //Sentence count period and a newline character.
        havepunct = true;
           if (c == '\n' && havepunct)
           {
               ++ sentences;
               havepunct = false;
           }
Either your teacher needs to be fired or instead of it being a sample code, you're supposed to fix all the errors to make it work. If the latter, you can start by defining c.
ifstream input( "testfile.txt");
bool havepunct = false;
sentences = 0;

while ((c=input.get()) != EOF)

if (c == '.') //Sentence count period and a newline character.
havepunct = true;
if (c == '\n' && havepunct)
{
++ sentences;
havepunct = false;
}

This is the overall sample.
Having it in a loop definitely makes more sense. c is still undefined though and although I can safely assume it is of type char, no compiler will. Assigning it to each new character makes sense as well instead of only the first one as in your first post w/out the loop. It might just be because I'm tired, but I don't understand the conditions for the second if and it still look like a "fix the errors" exorcise. You need to step through it yourself, in your head, on paper, or with a debugger (defining c will get you started on that). If I fix it for you, you learn nothing and fixing code is what a programmer does most of the time.
Topic archived. No new replies allowed.