The best solution will depend on the type of file you are counting words from and how you want to define a word. ASCII vs. Unicode. MS-Word docs vs. PDF files. It can get quite elaborate.
ASCII is the easiest to count groups of english letters with.
I would inc my counter on the first encounter of A-Z or a-z and skip everything else until I found a space, then skip any space characters until I encountered another alphabet character. Inc my counter again, rinse and repeat 'till you reach the end of the file.