I am not discovering the problem that is in my function, it does the following:
- I get a char array with
'\n'
at the end. - Then I go through the vector verifying:
- If you find in the vector the exclamation mark, end point, or question mark, that is, I found a sentence (phrase was defined as a word that ends with a dot an exclamation or a question mark), and I save the position of the vector;
- If I find a space, I simply keep the position;
- If I find a digit from 0 to 9, a lowercase letter or a capital letter, if
i = 0
, stop gets 0, otherwise, I simply save the position ofi
; - If I find a
\n
I end the loop by givingbreak
;
Well, the function is this, but it's looping, i
hangs depending on the phrase, but I'm not understanding why it's crashing, I'm not finding logic error.
Here is the code for the function:
int contagemFrases(char* p, int r) // Declaração da função que conta o número de frases presentes no texto.
{
int frases = 0, parada = 0, i;
for(i = 0; i < r; i = parada + 1)
{
if(p[i] == 46 || p[i] == 33 || p[i] == 63)
{
frases++;
parada = i;
}
else if(p[i] == 32)
parada = i;
else if (p[i] >= 48 && p[i] <= 57 || p[i] >= 65 && p[i] <= 90 || p[i] >= 97 && p[i] <= 122)
{
if(i == 0)
parada = 0;
else
parada = i;
}
else if(p[i] == '\n')
break;
}
return frases;
}