/* * Program to count alphabet characters in input file and produce output * file listing each letter found and how many times it was found. * * Program uses "tolower" to convert input characters to lower case and * only counts those for which the islower(result) is true. * * Program also prints to stdout the total number of characters in the * input file and how many were counted. * * Names of input and output files are given as command-line arguments. */ #include #include #include #include #include "alphacounters.h" int main(int argc, char * argv[]) { if (argc < 3) { printf("usage %s infile outfile\n", argv[0]); return 1; } FILE * infile = fopen(argv[1], "r"); if (infile == NULL) { printf("could not open %s\n", argv[1]); return 1; } int num_counters; letter_count_t * counters = build_alphacounters(&num_counters); if (counters == NULL) { printf("could not get space for %d counters\n", num_counters); return 1; } print_alphabet(stdout, counters, num_counters); /* * FIXME your code goes here * * outline: * * process infile a character at a time, incrementing counters * using update_counter() function * close infile * open output file, write nonzero counters to it, and close it * print counts of alphabetic and all characters */ free(counters); return 0; }