title: C: Why am I getting 'Floating Point Exception: 8' From This Calculation?
body: <p>Here is my function:</p>
  
  <pre><code>int scoreString(char *toScore) {
      int length = strlen(toScore);
      int score = 0;
      int spaceCount = 0;
      for (int i = 0; i &lt; length; i++) {
          char current = toScore[i];
          if (current == ' ') {
              spaceCount++;
          }
          score += scoreChar(current);
      }
      //English words are ~5 characters
      int charsPerWord = (length/(spaceCount + 1));
      if (charsPerWord &gt;=3 &amp;&amp; charsPerWord &lt;= 7) {
          //Big Bonus
          score = score * 2; //THIS LINE CAUSES PROBLEMS
      } else if (spaceCount &lt;= 1) {
          //Big penalty
          score = score / 2; //THIS LINE CAUSES PROBLEMS
      }
      return score;
  }
  </code></pre>
  
  <p>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 <code>Floating point exception: 8</code> after a few executions.  Any ideas?</p>