/* Assignment #1 - Fall 2024 This program processes an array of characters, and prints out the one with highest ASCII representation (as both its decimal value and the character), as well as the most popular character in the array. To compile this program: gcc -Wall -Werror -g -o a1 a1.c To run this program, you can specify 0 or 1 arguments: ./a1 ./a1 welcomeback ./a1 "Hello there!" */ #include #include /* * Finds the highest-valued character in a character array, * and returns that char. Returns -1 if the array is empty. * * arr: the character array * n: the number of elements in the array (an int) */ char find_highest_char(char arr[], int n) { char highest = 0; // TODO: Part A return highest; } /* * Finds the lowest-valued character in a character array, * and returns that char. Returns -1 if the array is empty. * * arr: the character array * n: the number of elements in the array (an int) */ char find_lowest_char(char arr[], int n) { char lowest = 127; // TODO: Part B return lowest; } /* * Finds the most common character in a character array, * and returns that char. Breaks ties by choosing the * lowest-valued char. Returns -1 if the array is empty. * * arr: the character array * n: the number of elements in the array (an int) */ char find_most_common_char(char arr[], int n) { // int freqs[128] = { 0 }; // think about how this may be useful to you char most_common = 0; // TODO: Part C return most_common; } /* * Prints out the statistics after parsing a character array. * * highest: the character with highest decimal value (a char) * lowest: the character with lowest decimal value (a char) * most_common: the character that appeared the most (a char) */ void print_results(char highest, char lowest, char most_common) { // TODO: Part D } // Leave this here: it's a nice way to test your individual functions // without dividing this code into multiple files; any code between // this and the corresponding #endif will be deleted during testing, // so don't put anything here that you need! #ifndef __TESTING__ /* * Run the program! This sets up the character array (a "string") to * parse, then calls the appropriate functions to do the actual work. */ int main(int argc, char **argv) { // Determine the string to parse char *s = NULL; if (argc == 1) { s = "Supercalifragilisticexpialidocious"; printf("The string to parse is: \"%s\"\n", s); } else if (argc == 2) { s = argv[1]; } else { fprintf(stderr, "You should run this program with at most one command-line argument. Good-bye!\n"); return 1; } // Call the functions to parse out the highest- and lowest-valued // character and the most popular character in the string char highest_char = find_highest_char(s, strlen(s)); char lowest_char = find_lowest_char(s, strlen(s)); char most_common_char = find_most_common_char(s, strlen(s)); print_results(highest_char, lowest_char, most_common_char); // Return 0 to indicate success return 0; } #endif // __TESTING__