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

  1. Complete the code as directed by the comments in the file;
  2. Add a file header comment with the usual information (file name, author, date, description); and
  3. 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.