Assignment Instructions

  1. Edit, compile, and run the following program on the UH UNIX shell:
    1. Read a Morse Code phrase from the commandline and decode the phrase into English.
    2. Check to make sure the user entered at least 2 commandline arguments. If not, print error message and end program.
    3. Do NOT use scanf() or getchar() for input for this program. The input for this program is ONLY from the commandline. For an example of commandline input, read and run this program: command.c
    4. Use string functions to compare strings, take the length of the string, add to a string, etc. See the example program: stringfunctions.c for examples of string functions.
      1. At a minimum, you need two nested for loops, and the strcmp() function to compare the argv[] array to the morse[] array.
      2. Functions strncpy(), strncat(), strcmp(), strstr(), and strtok() might also be useful for this assignment, as there are many different ways to write the code for this assignment..
      3. Here is some example code to give you an idea about how to access the Morse code array. The variable i is the index in a loop
        printf("complete string = %s\n", morse[i]);
        printf("first character = %c\n", morse[i][0]);
        printf("Morse code part = %s\n", morse[i]+2);
        printf("Morse code length = %d\n\n", strlen(morse[i])-3);
    5. Please use loops, instead of 36 if-statements or 36 case-statements.
    6. A basic program outline and with the Morse Code is posted below.
    7. Email your makefile and C program to the instructor.
  2. For the submission guidelines and the grading guidelines, see the syllabus.

Example I/O

walbritt@uhx01:/home/27/walbritt/ics212> ./program                                                     
ERROR: You only typed the executable. Enter the Morse Code on the commandline.

walbritt@uhx01:/home/27/walbritt/ics212> ./program .                                                   
e

walbritt@uhx01:/home/27/walbritt/ics212> ./program .-                                                  
a

walbritt@uhx01:/home/27/walbritt/ics212> ./program .----                                               
1

walbritt@uhx01:/home/27/walbritt/ics212> ./program .---- ..--- ...-- .- -... -.-.                      
123abc

walbritt@uhx01:/home/27/walbritt/ics212> ./program - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. 
thequickbrownfoxjumpsoverthelazydog

Program Outline

/*Command-line Morse Code: convert Morse Code to letters*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define SIZE 36

const char *morse[SIZE] = {
    "0 ----- ",
    "1 .---- ",
    "2 ..--- ",
    "3 ...-- ",
    "4 ....- ",
    "5 ..... ",
    "6 -.... ",
    "7 --... ",
    "8 ---.. ",
    "9 ----. ",
    "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 --.. ",
};

int main(int argc, char *argv[]){
    
    //error checking

    //loop through the commandline input

    //convert Morse Code to letter 
    
    return 0;
}