The Objective
The objective of this assignment is to become familiar using pointers and dynamic memory in a C application. By comparing their solution of this project with their solution to project 1, students will see and experience the close relationship between arrays and pointers in C. Students will also gain experience with command line arguments.The Task
A "tag cloud" is a visual representation of the words which occur most frequently in a document. High frequency words are displayed with larger font sizes and brighter colors. Lower frequency words are displayed with smaller font sizes. The websites www.wordle.net and www.tagcrowd.com generates tag clounds from text that you provide. The website http://chir.ag/phernalia/preztags shows a chronological tag cloud timeline for US Presidential speeches. You assignment is to write a program that tokenizes a text file (reads one "word" at a time) and generates the information required to create a tag cloud.
This project has the same basic functionality as project 1.
How does your program work?

Hints, Notes and Requirements
Requirements designated as (R
) are new for project 2.
) Dynamic memory allocation is required for all structs and arrays
This is ok: int *pScores = (int *)calloc( 42, sizeof(int) ); This is not ok: int scores[42];
This is ok: struct bob *pBob = (struct bob *)malloc( sizeof(struct bob) ): This is not ok: stuct bob aBob;
This is ok : Code that dynamically allocates an array of 55 pointers to struct bobs This is not ok: struct bob arrayOfBob[ 55 ]; This is not correct: struct bob *arrayOfBob = (struct bob *)malloc( 55 * sizeof(struct bob));
)
All dynamically allocated memory must be free'd so that no memory leaks
are created.
)
Your program must run cleanly under the Unix valgrind utility.
Execute your program under control of valgrind with the command
linxu2[2]% valgrind --leak-check=full project2 textfileThe result should look something like this
==3290== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 1) ==3290== malloc/free: in use at exit: 0 bytes in 0 blocks. ==3290== malloc/free: 355 allocs, 355 frees, 5,329 bytes allocated. ==3290== For counts of detected errors, rerun with: -v ==3290== All heap blocks were freed -- no leaks are possible.See the course resources page for a link to a valgrind tutorial and / or see the on-line Unix manual for help with valgrind.
) Your code must be separated into multiple .c files as follows.
Appropriate .h files are also required. You are free to choose any names for your files.
) You must submit a makefile that creates
an executable named project2 just by typing
make at the Unix promt. A skeleton makefile is available in Mr. Frey's
public directory /afs/umbc.edu/users/f/r/frey/pub/313/proj2/ Project Grading
The expected point breakdown for this project will be something like this. Since the functionality of the program is the same as project 1, the focus of this project's grading is on coding.Extra Credit (5 points)
The most common multi-purpose sorting algorithm used in programming applications is known as "quicksort". Quicksort is generally the fastest sorting algorithm for most applications. It uses a technique known as "partitioning". The quicksort algorithm is available in the standard C library under the name qsort( ). qsort( ) is discussed briefly in K & R (section 5.1 and appendix B5) and in the Unix on-line manual (man qsort). A quick look on the internet using Google will bring up many pages devoted to quicksort. qsort can be used to sort an array of any type so its prototype needs some explanation.The prototype for qsort( ) in the C library (in <stdlib.h>) is
void qsort( void *base, size_t n, size_t size, int (*cmp)(const void *p1, const void *p2)); where void *base is a pointer to (i.e. the name of) the array of elements to be sorted size_t n is the number of elements in the array size_t size is the size (in bytes) of each element in the array int (*cmp)(const void *p1, const void *p2) is a pointer to (i.e. the name of) a user-defined function whose parameters are pointers to elements in the array to be compared. To sort the array in ascending order, the function must return < 0 if the element pointed to by p1 is "less than" the element pointed to by p2 > 0 if the element pointed to by p1 is "greater than" the element pointed to by p2 0 if the elements pointed to by p1 and p2 are "equal"For 5 points of extra credit, have your code call qsort( ) from the C library to do your sorting. You will of course have to write the necessary comparison functions for qsort to use. Note that qsort calls your function with pointers to the elements (p1 and p2) to compare. If your elements are themselves pointers, then the parameters passed to your comparision functions are really pointers to pointers to elements to be compared. Fun stuff !!
Submitting the Program
You can submit your project using the submit command.
submit cs313 Proj2 <list of files>
You may submit your project as often as you wish -- only the last submital will be graded. See this page for a description of other project submission related commands. To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show all files that you submitted in a format similar to the Unix 'ls' command.
submitls cs313 Proj2