Here is my function:
int scoreString(char *toScore) {
int length = strlen(toScore);
int score = 0;
int spaceCount = 0;
for (int i = 0; i < length; i++) {
char current = toScore[i];
if (current == ' ') {
spaceCount++;
}
score += scoreChar(current);
}
//English words are ~5 characters
int charsPerWord = (length/(spaceCount + 1));
if (charsPerWord >=3 && charsPerWord <= 7) {
//Big Bonus
score = score * 2; //THIS LINE CAUSES PROBLEMS
} else if (spaceCount <= 1) {
//Big penalty
score = score / 2; //THIS LINE CAUSES PROBLEMS
}
return score;
}
If I get ride of the two lines that are marked as causing problems, everything is dandy. The output of this function without them ranges from 100-2000 on the input I'm testing so this should not be an overflow error ... if I leave either of those two lines in I get Floating point exception: 8
after a few executions. Any ideas?