I am writing a program to take a users input and turn it into Morsecode as an output. I have a few errors that are popping up in my program. I am unsure as what i should do or try from here. I have the conversions done from the alphabet to morsecode. I switched from using letters to the binary input because it was not liking the letters.
I was trying to scan for the phrase and use a string to store it in. Then using a for loop to increment string[i] up 1 each loop so it would check each address of the string. each time the loop would run it would store the string value in a INT A then go check in the if= else - if statements for a match and return and print the value.
# include <stdio.h>
void checkphrase ( char string[], int *px)
{
int i;
printf(" PHRASE ENTERED IS\n %s\n" , string[i]);
/* Prints the Phrase entered */
/* Start for loop to compare letters to the morse code equivalent */
for( i=0; i <= 30; i++)
{
px = string[i]; // pointer points the string value
a = px; // int a is assgined the value of px to be compared to morsecode
findmorse() // calls function to compare morsecode
}
return 0; // returns to main
}
void findmorse (int a)
/* originoally had a = the aphpabet but converted to binary */
{
if (a == 01000001)
Printf(" • — \n");
else if (a == 01000010)
Printf(" — • • • \n");
else if (a == 01000011)
Printf(" — • — • \n");
else if (a == 01000100)
Printf(" — • • \n");
else if (a == 01000101)
Printf(" • \n");
else if (a == 01000110)
Printf(" • • — • \n");
else if (a == 01000111)
Printf(" — — • \n");
else if (a == 01001000)
Printf(" • • • • \n");
else if (a == 01001001)
Printf(" • • \n");
else if (a == 01001010)
Printf(" • — — — \n");
else if (a == 01001011)
Printf(" — • — \n");
else if (a == 01001100)
Printf(" • — • • \n");
else if (a == 01001101)
Printf(" — — \n");
else if (a == 01001110)
Printf(" — • \n");
else if (a == 01001111)
Printf(" — — — \n");
else if (a == 01010000)
Printf(" • — — • \n");
else if (a == 01010001)
Printf(" — — • — \n");
else if (a == 01010010)
Printf(" • — • \n");
else if (a == 01010011)
Printf(" • • • \n");
else if (a == 01010100)
Printf(" — \n");
else if (a == 01010101)
Printf(" • • — \n");
else if (a == 01010110)
Printf(" • • • — \n");
else if (a == 01010111)
Printf(" • -- \n");
else if (a == 01011000)
Printf(" -• • - \n");
else if (a == 01011001)
Printf(" -• -- \n");
else if (a == 01011010)
Printf(" --• • \n");
/* Numbers */
else if (a == 1)
Printf(" · – – – – \n");
else if (a == 2)
Printf(" · · – – – \n");
else if (a == 3)
Printf(" · · · – – \n");
else if (a == 4)
Printf(" · · · · – \n");
else if (a == 5)
Printf(" · · · · · \n");
else if (a == 6)
Printf(" – · · · · \n");
else if (a == 7)
Printf(" – – · · · \n");
else if (a == 8)
Printf(" – – – · · \n");
else if (a == 9)
Printf(" – – – – · \n");
else if (a == 0)
Printf(" – – – – – \n");
/* return to check phrase */
return string[};
}
int main() // main function
{
printf("PLEASE ENTER A PHRASE UNDER 30 CHARACTERS\n");
scanf(" %s " , string[]);
checkphrase () // takes string to the checkphrase function
return 0;
}