UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | lectures | news | help

Project 3: Morse Code

Due date: Wednesday, November 11, 1998

Important: Revision of a required function's prototype made on 11/2. See below.

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 ..- This project will give you some experience with file-handling, malloc, strings, characters, and pointers. Of course, it will also test function writing, separate compilation and design.

Description of the Program

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.

To be more specific, your project is to ask the user for the name of the file, read in the contents of the file, and translate it from English into Morse code. Your program should also report the number of spaces, punctuation marks, and the number of other non-alphabetic characters that exist in the file.

You will need to open the file and progress through it counting the characters as you go. Don't try to store the characters on the first pass through the file, just count the characters. After the length of the file has been determined, you should use malloc to allocate space that is exactly the correct size to hold the contents of the file in a string. You can get back to the beginning of the file by using rewind and then read a character at a time into the string.

Your project must contain the two functions that I have described below. Design will begin to count towards your grade with this project, so I would imagine that you may have other functions as well. Separate compilation is required. The required functions are called ReadFile() and CountNonAlpha(). These functions are described below and the prototypes are given.

char* ReadFile (int *lengthPtr); The prototype for CountNonAlpha has changed 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.

Sample Output

retriever[102] a.out Enter the name of the text file to be examined: morse.txt 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 : - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. retriever[103]

More details

Obtaining the 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.

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.

CSEE | 201 | 201 F'98 | lectures | news | help