OK, before we start, let's remind ourselves that I'm a hardware designer by trade. When it comes to software in general — and C in particular — I know only enough to be dangerous.
I have a project on the go at the moment. This is a secret squirrel project whose purpose — for the present — must remain a riddle, wrapped in a mystery, inside an enigma. Suffice it to say that I wish to use a light-emitting diode LED to flash messages in Morse code.
My question pertains to the best way in which to represent, store, and access the Morse code dots and dashes used to represent the numbers and letters.
Ultimately, I want to be able to initialize a string with a message I wish to transmit using a statement like:
char my_string = "HELLO WORLD";
Later, I'll pass this string as a parameter into the function that will actually flash the LED. So, once again, my question is: “What's the best way to represent the dots and dashes associated with the various characters?” My very first pass thought was to store these as character strings themselves — something like the following:
char string_A = ".-";
char string_B = "-...";
char string_C = "-.-.";
I know that this technique of using a separate character for each dot and dash doesn’t give the smallest memory footprint, but it does have the advantage of understandability, which is, of course, an important consideration. On the other hand, the scheme shown above — having individual strings for each of the character — would be difficult to use.
The bottom line is that every approach I can think of is less than optimal or incongruous, which is why I'm inviting your ideas. If you think of anything — preferably pertaining to this perplexing poser — please post it as a comment below and/or email me at firstname.lastname@example.org.