If you've been waiting for me to finish writing the assignment description here, I'm now finished (unless I need to clarify something here).
In this assignment, you'll gain experience with recursive data structures, compiling multiple source files, and reading from files.
Your program will prompt the user for the name of a text file. (You may read the filename from the command line instead if your development environment allows you to run your program with a command line.) The named file will contain a list of words, one per line. Your program will then read in the file, building a doubly-linked list of nodes in memory, each of which contains a string (a character pointer---you should dynamically allocate it rather than using a fixed size), a counter, and pointers to the next and previous nodes in the list, of course. The nodes will store words and the number of times the word has been found. Words in the file may contain uppercase letters, and you should convert all letters to lowercase before storing them in your list.
So you'll write a function to read a word from the file, converting letters to lowercase. You may read it into a constant-sized array, ignoring any letters that don't fit in the array. And you'll write a function to traverse the linked list; if the word is found in the list, it will increment the counter and possibly swap it with one of its neighbors until proper ordering of the counters is restored. (Realize that a word may have to move more than one position in the list if multiple words have the same frequency.) If the word is not found, create a new node and put it on the end of the list.
After the list is built, you should write a second source file bargraph.c that contains one publicly accessible function bargraph() with the following prototype:
void bargraph(int numbars, struct barinfo[]);
where struct barinfo is defined as
struct barinfo { char *label; int barlength; };
The function bargraph() draws a labeled bargraph of the numbars elements in the array barinfo, scaling the bar lengths so that the longest bar (not necessarily the first bar!) has a constant (70-78 character) width:
Bar label 1 - 56 ################################################ Bar label 2 - 70 ###################################################################### Bar label 3 - 24 #####################
Notice that each bar is preceded by its label and the (unscaled) bar length. You may use different symbols for each bar, if you wish. Write and use an appropriate header file associated with bargraph.c --- see me or Section 4.5 of K&R if you don't remember how they are used.
Your main source file will call bargraph() with an array of the ten most frequent words.
Remember to consider the functional decomposition of the problem; write each function to perform one function, so to speak. Write your program function-by-function, and test each before moving on. Use constants to avoid the use of magic numbers. And perform error checking whenever you call a function that can return an error code.
This assignment is due in printed form with sample output on Monday, February 22, in my office in Upson 5162, or you may submit it in class on Friday, February 19. Start early, and come to class or office hours with questions.