title: Counting alphanumeric characters in a text file in C++
body: <p>I wrote a program for counting the number of alphanumeric characters in a text file. However, the number it returns is always larger than the number that online character counters return.</p>
  
  <p>For example, the program will calculate the number of alphanumeric characters in this text:</p>
  
  <blockquote>
    <p>if these people had strange fads and expected obedience on the most
    extraordinary matters they were at least ready to pay for their
    eccentricity</p>
  </blockquote>
  
  <p>to be 162. Running the program again, it'll say there are 164 characters in the text. Running it again, it'll say there are 156 characters. Using <a href="http://www.lettercount.com/" rel="nofollow">this</a> online character counter, it seems that the character count ought to be lower than 144 (the online character counter includes spaces as well). </p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cctype&gt;
  using namespace std;
  
  int main() {
      char line[100];
      int charcount = 0;
      ifstream file("pg1661sample.txt");
      while (!file.eof()) {
          file.getline(line, 99);
          for (int i = 0; i &lt; 100; i++) {
              if (isalnum(line[i])) {
                  charcount++;
              }
          }
      }
  
      cout &lt;&lt; endl &lt;&lt; "Alphanumeric character count: " &lt;&lt; charcount;
      cin.get();
      return 0;
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>