Comments

repeat 'nbytes' times{ c = read one character from file if (c is a word character) { ++token if (token is 1) ++nwords } else { token=0 }};; Function to check if c is a word character;bool IsWordChar (c){ if (c is underscore) return true; if (c is digit) return true; if (c is lowercase character) return true; if (c is uppercase character) return true; return false;}[/code][color=Blue]FASM is so much easier to use.[/color]

filesize in bytes divided by 2 == number of words in file... LOL but seriously. It depends on your definition of a word and on what type of file. You could simply scan for the value 20h (space) and count every one you see. But that would only work in very limited situations. AsmGuru got the general purpose algorithm up already...

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.