#include "stdio.h" #include "ctype.h" main() { char c; int j; double count[26]; for (j = 0 ; j < 26 ; j++) count[j] = 0.0; while ((c = getchar()) != EOF) { if (isalpha(c) != 0) { count[tolower(c)-'a'] = count[tolower(c)-'a'] + 1.0; } } printf("\n"); for (j = 0 ; j < 26 ; j++) printf("%c %6.lf\t", j+'a', count[j]); printf("\n"); }
You can compile this program yourself, calling it FREQ.EXE, or download ours. To perform a frequency count on a text file named MESSAGE.TXT, you would type
FREQ <MESSAGE.TXT.
On a machine with a moderate speed hard-drive, the 800 page document took about a minute to count. You can also download this document as a 750 K zip file, if you want.