title: C program that counts the number of characters, words and lines in a given text, that may have blank lines?
body: <p>Here are the specifications.</p>
  
  <p>Every byte read from stdin counts as a character except EOF. Words are defined as contiguous sequences of letters (a through z, A through Z) and the apostrophe ( ', value 39 decimal) separated by any character outside these ranges.
  Lines are defined as contiguous sequences of characters separated by newline characters ('\n').
  Characters beyond the final newline character will not be included in the line count.</p>
  
  <p>My code seems to work for simple inputs, but when I try to input a large file with multiple paragraphs separated by blank lines my numbers are thrown off, with the word count and character being too high.</p>
  
  <p>So far I have</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
  
     char ch;
     unsigned int long linecount, wordcount, charcount;
     int u;
     linecount=0;
     wordcount=0;
     charcount=0;
  
  
     while((ch=getc(stdin))!=EOF){
  
  
         if (ch !='\n') {++charcount;}
         if (ch==' ' || ch=='\n') {++wordcount;}
         if (ch=='\n') {++linecount;}
  
       }
     if(charcount&gt;0){
        ++wordcount;
        ++linecount;
     }
  
     printf( "%lu %lu %lu\n", charcount, wordcount, linecount );
  
     return 0;
  
  }
  </code></pre>