0

这是我的功能:

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执行几次之后。有任何想法吗?

4

0 回答 0