我正在编写一个程序,以获取用户输入并将其转换为Morsecode作为输出。我的程序中出现了一些错误。我不确定我该做什么或从这里开始尝试。我已经完成了从字母表到更多代码的转换。我从使用字母切换到二进制输入,因为它不喜欢字母。
我正在尝试扫描短语并使用字符串来存储它。然后使用for循环将string[i]每循环增加1,这样它就会检查字符串的每个地址。每次循环运行时,它都会将字符串值存储在INT a中,然后在if= else - if语句中检查是否匹配,并返回并打印该值。
# include <stdio.h>
void checkphrase ( char string[], int *px)
{
int i;
printf(" PHRASE ENTERED ISn %sn" , 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 CHARACTERSn");
scanf(" %s " , string[]);
checkphrase () // takes string to the checkphrase function
return 0;
}
findmorse
需要参数
void findmorse (int a)
在checkphrase
中,你叫它没有一个。
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
在main
中,你的函数参数中有奇怪的括号。
scanf(" %s " , string[]);
然后checkphrase
可能需要声明接收的一些参数和表达式语句的终止分号(;
)。
checkphrase () // takes string to the checkphrase function
您需要启用(或注意)编译器警告(gcc -Wall -Wextra
)