3
I’m not figuring out the problem that’s in my job, she does the following:
- I get a char vector with the
'\n'
in the end. - Then I run the vector by checking:
- If you find in the vector the exclamation point, endpoint, or question mark, that means that I found a phrase (phrase was defined as a word ending with a dot an exclamation or a question mark), and I keep the position of the vector;
- If I find a space, I simply hold 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 hold the position ofi
; - If I find one
\n
I end the loop by giving abreak
;
Well, that’s the job, but she’s giving a bow, the i
hangs depending on the phrase, but I’m not understanding why it’s crashing, I’m not finding the error of logic.
Below is the function code:
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;
}
You agree that regardless of (i == 0) a
parada
will always receivei
? Just an observation, it’s not the problem– Maicon Carraro
But if it is going through the vector, then it always keeps the current position still, right?? because it is always guarding 1??
– Gabriel Vinicius
What’s the point of
parada
?– Maicon Carraro
A hint: your comment on the function side is redundant. Do not need it to know that has a function statement on the :) It would be better to make a comment saying what the function ago. What do the input parameters mean? And the output value? Does the function have any side effects (like printing on the screen or changing the value of a global variable)? Notice that I said "what," not "how," which is something code C can already explain on its own. I have to confess that I still can’t understand what your job is for...
– hugomg
Have an example of a function call where your program hangs?
– user25930