这是我的功能:
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;
}
如果我乘坐被标记为导致问题的两条线路,那么一切都很花花公子。没有它们的这个函数的输出在我测试的输入上的范围是100-2000,所以这不应该是溢出错误...如果我离开这两行中的任何一行,我会在几次执行后得到Floating point exception: 8
。有什么想法吗?