I have wrote the programming code that converts english to morse, but how do i go back the other way. This function does not read or write to files.
Code:
void morse_code_letters(char morse_strings[91][6])
{
//morse code letters using string copy
strcpy (morse_strings['A'], ".-");
strcpy (morse_strings['B'], "-...");
strcpy (morse_strings['C'], " -.-.");
strcpy (morse_strings['D'], "-.. ");
strcpy (morse_strings['E'], ".");
strcpy (morse_strings['F'], "..-.");
strcpy (morse_strings['G'], "--.");
strcpy (morse_strings['H'], "....");
strcpy (morse_strings['I'], "..");
strcpy (morse_strings['J'], ".---");
strcpy (morse_strings['K'], "-.-");
strcpy (morse_strings['L'], ".-..");
strcpy (morse_strings['M'], "--");
strcpy (morse_strings['N'], "-.");
strcpy (morse_strings['O'], "---");
strcpy (morse_strings['P'], ".--.");
strcpy (morse_strings['Q'], "--.-");
strcpy (morse_strings['R'], ".-.");
strcpy (morse_strings['S'], "...");
strcpy (morse_strings['T'], "-");
strcpy (morse_strings['U'], "..-");
strcpy (morse_strings['V'], "...-");
strcpy (morse_strings['W'], ".--");
strcpy (morse_strings['X'], "-..-");
strcpy (morse_strings['Y'], "-.--");
strcpy (morse_strings['Z'], "--..");
// morse code numbers using string copy
strcpy (morse_strings['1'], ".----");
strcpy (morse_strings['2'], "..---");
strcpy (morse_strings['3'], "...--");
strcpy (morse_strings['4'], "....-");
strcpy (morse_strings['5'], ".....");
strcpy (morse_strings['6'], "-....");
strcpy (morse_strings['7'], "--...");
strcpy (morse_strings['8'], "---..");
strcpy (morse_strings['9'], "----.");
strcpy (morse_strings['0'], "-----");
// morse code characters using string copy
strcpy (morse_strings['.'], ".-.-.-");
strcpy (morse_strings[','], "--..--");
strcpy (morse_strings['?'], "..--..");
strcpy (morse_strings[' '], " ");
}
Code:
char* letter_to_morse(char *morseTester1, char morse_strings[91][6])
{
int len = strlen(morseTester1);
char *result = malloc(len * 6 + 1);
int i;
*result = NULL;
for (i = 0; i < len; i++)
{
strcat(result, morse_strings[toupper( morseTester1[i++])]);
}
return result;
}
NOTE: char *morseTester1 = "Hello world"
I need to know how to convert from morse to english
Thanks!