/* Program to calculate dictionary word lengths. John Nordlie, November, 2011 */ #include #include #include #define MAXSIZE 255 int main() { char word[MAXSIZE], *p; FILE *infile, *outfile; int i, lengths[MAXSIZE], longest = 0; /* open files, exit if problem */ infile = fopen("dict.txt", "r"); if (infile == NULL) return 0; /* zero lengths */ for (i=0; i longest) longest = strlen(word); } /* end while loop */ fclose(infile); outfile = fopen("word_freq.txt", "w"); if (outfile == NULL) return 0; fprintf(outfile, "Word length Number of words of that length\n"); for (i=0; i < longest + 1; i++) fprintf(outfile, "%d %d\n", i, lengths[i]); fclose(outfile); } /* end main */