You are asked to write a Morse encoder/decoder program.
The program should have a menu to present the options:
- e - encode a line of text
- d - decode a line of text
- i - encode a text file
- f - decode a text file
- ? - print this menu
- q - quit
- e prompts for text to encode and converts the line read in from the keyboard.
- d prompts for text to decode and converts the line read in from the keyboard.
- i prompts for the name of a file to convert and reads in the file and displays
the original file and the encoded version of the file
- f prompts for the name of a file to convert and reads in the file and displays
the original file and the decoded version of the file
How do you begin such a program?
There are many ways to break it up.
Let’s step through the development process.
- 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 --..
- <space> $$
- For our first step, lets create a program that reads in a line from the
keyboard and encodes it.
- Once this works, we can move the encoding code in to a function.
- Once this works, we can move on and add to our program
Now let’s add the decoding ability.
- Ok, we can encode and decode. Now lets get our program to loop, prompting the
user for the next command. We’ll also implement the printMenu since that’s
pretty easy (printf statements).
Notice that we put stubs in our switch for encoding/decoding a file, and
merely print out that this function isn’t implemented yet.
- All right, we’re almost done. Now we need to add the file functions.
Here’s the final version.