I created a function that should count the number of sentences in a given string. I used “.”, “!” , “?” to determined whether or not a sentence has ended. Since it runs, I think I’m on the right track, it’s just the result is wrong.
int calc_sent(string text)
{
int numSent = 0;
for(int i = 0; i < txtLength; i++)
{
if (strcmp( &text[i], "<") == 0 || strcmp( &text[i], "?") == 0 || strcmp( &text[i], "!") == 0)
{
numSent++;
}
}
return numSent;
}
I used this text to test it: “My name is John. His name is Jack! Her name is Jane?”. Instead of 3 sentences, the result comes back as 1.
Any suggestions on what could be wrong?
New contributor
SGhostCode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1