Hi,
I am working on a small program that converts English to Morse code and back into English. The input is read from a file specified by the user no matter which way the conversion is going. I figured out the english to morse conversion pretty easily, by just reading character by character and converting into the corresponding morse code string using a two dimensional array. However I am having trouble reading the morse strings and converting them back into english using the strcmp function. I have tried both reading character by character in a loop and concatenating and reading string by string with little luck. I am thoroughly confused and any suggestions are much more than appreciated. I will attach all the code that I have tried using up until this point. Thanks in advance for any suggestions.
this is the conversion function:
void morse_to_english(char morse_strings[91][6], FILE *outfile, FILE *infile)
{
int count = 0;
char character = '\0', morse[6];
read_string(morse, infile);
while (count < 91)
{
if (strcmp(morse, morse_strings[count]) == 0)
{
character = count;
fprintf(outfile, "%c", character);
count = 91;
}
else
{
count++;
}
}
}
The hard coded 91 is there because the morse_strings array has 91 rows.
This was my method for reading strings from the file:
void read_string (char morse[6], FILE *infile)
{
fscanf(infile,"%s", morse);
}
and here is how I called the function in main using an end-file controlled loop:
while (!feof(infile))
{
morse_to_english(morse, morse_strings, outfile, infile);
count++;
}
Like i said above all suggestions are appreciated.