You can use
tolower
and that will allow the user to enter either case of letter. You could also use an array indexing scheme if you want to. The goal would be to avoid using a switch-case statement. Here's one way you can have a function that returns the Morse code string for a given character using two arrays. The arrays are sorted according to the alphabetic and numeric orders of the characters so that indexes can be used to access them.
typedef const char * PCSTR;
PCSTR GetMorseCodeString( int character )
{
static PCSTR letterStrings[] =
{
".-" , "-..." , "-.-." .................
, "--.." };
static PCSTR numberStrings[] =
{
"-----" , ".----" , "..---" .................
, "----." };
int lowerCase;
int index;
if( character >= '0' ) && ( character <= '9' ) )
{
index = character - '0'; return numberStrings[ index ];
}
lowerCase = tolower( character );
if( character >= 'a' ) && ( character <= 'z' ) )
{
index = character - 'a'; return letterStrings[ index ];
}
return nullptr; }
Then you need to prompt the user for an input string and translate each character of the string into its Morse code equivalent by calling this function. Alternatively, you can read a file of text strings and translate each one the same way.