我正在编写一个程序来获取用户输入并将其转换为摩尔斯电码作为输出。我的程序中出现了一些错误。我不确定我应该做什么或从这里尝试。我已经完成了从字母表到莫尔斯电码的转换。我从使用字母切换到二进制输入,因为它不喜欢字母。
我试图扫描短语并使用字符串将其存储在其中。然后使用 for 循环将 string[i] 每个循环增加 1,以便检查字符串的每个地址。每次循环运行时,它将字符串值存储在 INT A 中,然后检查 if= else - if 语句是否匹配并返回并打印该值。
# 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;
}