Help counting sentence

Hello! I am making a project for Programming 1. I need to count sentences, they need to start with a capital letter and finish with a dot. My code works if a write this "This is a Test.", because the last word starts with a capital T. But with "This is a test." It will count zero.


I dont realize what to do, how to differenciate the first letter of the sentence with the first letter of the last word of the sentence.

Sorry for my english! Booleans and print are in spanish :D

Thank you!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
i=0;
    while(s[i] != '\0'){
        if (inicio_oracion == TRUE){
            if((s[i] >= 'a') && (s[i] <= 'z')){
                es_oracion = FALSE;
            }
            inicio_oracion = FALSE;
        }
        else{
            if(s[i+1] == ' ' || s[i+1] == '\0'){
                if(s[i] != '.'){
                    es_oracion = FALSE;
                }
                else{
                    if(es_oracion == TRUE) {
                        contador_oraciones++;
                    }
                }
            }
        }
        if(s[i] == ' '){
            inicio_oracion = TRUE;
            es_oracion = TRUE;
        }
        i++;
    }
    printf("\nLa cantidad de oraciones es %d\n\n", contador_oraciones);
On the basis of your question you could just count the dots.

However, sentences end with a lot of other punctuation (?! etc), as well as using the occasional ellipsis (...)
Yeah, but it has to start with a capital letter and end with a dot to be a sentence in this case, and the professor its only going to check for dots, no other punctuation!
Find next capital letter. Find next dot. Increment a counter.
Find next capital letter. Find next dot. Increment a counter.
...
Keep going until the end of the string.


Still quicker just to count the dots, though.
I made something like this, and for the tests I did it works.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    i=0;
    while(s[i] != '\0'){
        if((s[i] >= 'A') && (s[i] <= 'Z')){
            count_caplet++;
        }
            if(s[i] == '.'){
                count_dot++;
            }

        i++;
    }
    if (count_caplet == count_dot){
            count_sentence = count_caplet;
    }
    printf("\nLa cantidad de oraciones es %d\n\n", count_sentence);


It has any flaws? I think its fine for Programming 1, of course if I put My name is Maximiliano..its going to count as 2 sentences.
Any way I can prevent that?
Last edited on
Topic archived. No new replies allowed.