UMBC CS 201, Spring 03
UMBC CMSC 201 Spring '03 CSEE | 201 | 201 S'03 | lectures | news | help

CMSC 201
Programming Project Four

Morse Code

Out: Monday 4/14/03
Due: before Midnight, Sunday 4/27/03

The design document for this project, design4.txt ,
is due: Before Midnight, Monday 4/21/03

Further Specifications section added Thu Apr 17 10:30:20 EDT 2003

The Objective

This project will give you some experience with command-line arguments, file-handling, malloc, strings, characters, and pointers. Of course, it will also test function writing, separate compilation and good design techniques.

The Background

Morse code, patented by Samuel F. B. Morse in 1837, is the language that was used to send messages by telegraph from the middle of the nineteenth century until the advent of the modern telephone and today's computer-controlled communications systems. In Morse code, each letter in the alphabet is represented by a series of dots and dashes as shown in the table below: A .- H .... O --- V ...- B -... I .. P .--. W .-- C -.-. J .--- Q --.- X -..- D -.. K -.- R .-. Y -.-- E . L .-.. S ... Z --.. F ..-. M -- T - G --. N -. U ..-

The Task

This project is to read the contents of a file into a string, give a report of the kinds of characters in that string and then print out its Morse code equivalent. There is a text file, called morse.txt, that I have made available to you for this project. There is a link to it further down in the project description.

Your project is to get the name of the file as a command-line argument, read in the contents of the file, and translate it from English into Morse code. Your program should also report the total number of characters in the file, print the contents of the file, report the number of spaces, punctuation marks, and the number of other non-alphabetic characters that exist in the file.

Your project MUST contain the two functions called ReadFile() and CountNonAlpha() that I've specified the prototypes and described below. You may not alter these prototypes in any way. You will certainly need to have other functions as well.

void ReadFile (char *filename, char **stringPtr, int *lengthPtr); void CountNonAlpha (char *str, int length, int *spacePtr, int *punctPtr, int *otherPtr);

When printing the Morse code translation of the sentence, separate the code for each letter with a space. Each word should be shown on a separate line. All other non-alphabetic characters that occur in the string should be ignored when translating it into Morse code.

Further Specifications

Sample Output

linux1[102] a.out morse.txt Your greeting goes here The string is : The quick brown fox jumps over the lazy dog. It consists of 45 characters. There are 9 space(s), 1 punctuation mark(s), and 0 other non-alphabetic characters. In Morse code this is : - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. linux1[103]

Obtaining the data file

The file to use for this project is called morse.txt. The executable and the data file need to be in the same directory in order for the program to run properly. As in the previous project, you should get a copy of this file by using the Unix cp command shown below.

cp /afs/ .

What to Turn In

You must use separate compilation for this project. You may have as many .c and .h files, as you see fit.

Use the submit command to submit your files as in previous projects. Make sure you submit all files necessary for your project to compile, including your header file(s).

CSEE | 201 | 201 S'03 | lectures | news | help