I'm making a morse code translator through the command line but am having trouble comparing the array holding user input to the array holding the morse code equivalents.
const char *morse[SIZE] = {
"0 ----- ",
"1 .---- ",
"2 ..--- ",
"3 ...-- ",
"4 ....- ",
"5 ..... ",
"6 -.... ",
"7 --... ",
"8 ---.. ",
"9 ----. ",
"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 --.. ",
};
int main(int argc, char *argv[])
{
int i=0;
for (i = argc-1; i >=0; i--)
{
argv[i] = argv[i];
printf("%s\n", argv[i]);
}
if (argc < 3)
{
printf("Need atleast two arguments");
return 0;
}
for (int i = argc-1; i >= 0; i--)
{
for (int ii = 0; ii <= SIZE; ii++)
{
char *pointer = strstr(morse[ii], argv[i]);
if ( pointer!=NULL)
{
printf("%c", *morse[ii]);
}
}
}
So if the user entered ".-" which is stored in the argv array, my for loop would go through morse and use the strstr to find ".-", and then it would print the first char which would be "a". I can't seem to successfully print out the first char in the morse array and I'm guessing it has to do with strstr.