/* * functions for use with programs that count alphabetic characters */ #ifndef ALPHACOUNTERS_H /* just in case we forget and #include this twice */ #define ALPHACOUNTERS_H #include #include /* * struct to hold character and count */ typedef struct { char letter; long count; } letter_count_t; /* * function to build array of counter structs, with one entry for each * character c for which islower(c) is true. * * sets *sz to the number of entries needed, and returns pointer to * array or NULL if space for it could not be obtained using malloc(). */ letter_count_t * build_alphacounters(int *sz); /* * function to print characters in array of counter structs, all on one * line. */ void print_alphabet(FILE * f, letter_count_t counters[], int num_counters); /* * function to update one element of an array of counters built by * build_alphacounters. * * parameter ch gives the (lowercase) character for which the counter * should be incremented. * * parameter incr says how much to increment it. * * parameters counters and counters_sz give the array of counters and * its size. */ bool update_counter(char ch, int incr, letter_count_t counters[], int num_counters); #endif