CMSC 104, Spring 2014
Homework 4
Out: Monday 4/28/14
Due: Before 11:59 PM on Monday, 5/5/14
Note that late homeworks will NOT be accepted.
The Objectives
The objective of this assignment is to become familiar with the use of arrays in C -- how they are declared, initialized, and used.
The Assignment
The C source file hw4.c contains a program to count the characters (A-Z) in an input file and print a text histogram of the character counts. Unfortunately, the program is incomplete: there are six places in the file where you must provide the missing C code. The places where you need to write code are clearly marked with comments.
Note: you can download a copy of the file to your linux account using the command:
wget http://userpages.umbc.edu/~cmarron/hw4.c
For your assignment to be complete, you must
- Complete the code as directed by the comments in the file;
- Add a file header comment with the usual information (file name, author, date, description); and
- Add any additional comments that would help a reader understand the code.
Be sure that you completed program compiles and runs. You can use the completed program to count the characters in a file using I/O redirection. For example, to count the letters in inputfile.txt, use the command:
linux1[11]% ./a.out < inputfile.txt
If your code is correct, it should produce output like the following:
linux1[12]% gcc -Wall -ansi hw4.c linux1[13]% ./a.out < inputfile.txt A: ********************************************************* B: ** C: ***************************** D: ******************** E: ****************************************************************** F: ************************ G: *************** H: ************************** I: ********************************************************* J: K: L: ********************** M: *************** N: ****************************************** O: ************************************ P: ******************** Q: ** R: ***************************************************** S: ******************************* T: ***************************************************** U: ****************** V: * W: ******** X: **************** Y: **************** Z:
Submit your work
Be sure that your completed program is called hw4.c
and is in
your hw4
directory. The next step is to submit your work.
- Change to the
hw4
directory (usepwd
to check that you have done this correctly) and then submit the files to the projecthw4
using the command:linux1[6]% submit cmsc104_cmarron hw4 hw4.c linux1[7]%
- You can use the
submitls
command to check that you have submitted both files:linux1[8]% submitls cmsc104_cmarron hw4 total 5 drwxr-xr-x 2 cmarron rpc 2048 Mar 25 14:05 . drwxr-xr-x 43 cmarron rpc 2048 Mar 25 14:05 .. -rw-r--r-- 1 cmarron rpc 1858 Mar 25 14:05 hw4.c