我已经做了一些代码,但它没有正确运行
到目前为止我做了什么
void keyread1(void)
{
char *string1= (char*) malloc (20);//char pointer pointing to allocated memory
char *string2= (char*) malloc (20);
char *string3= (char*) malloc (20);
char *string4= (char*) malloc (20);
string4[0]='\0';
printf("Enter word to convert to morse code: \n");
scanf("%s", string1);
while (string1!='\0')
{
int z=0,a=0;
strncpy(string2+a, string1+z,4 );
string3=morse2english(string2);
strncat(string4+a,string3,1);
z=z+4;
}
printf("morse code string: %s\n",string4);
free(string1);
return;
}
char *morse2english(char *morsecode)
{
int j=0;
int a=0;
char *azarray=(char*)malloc(26);
strcpy(azarray, "abcdefghijklmnopqrstuvwxyz");
char *morsearray=(char*)malloc(104*sizeof(char));
strcpy(morsearray, ".- -...-.-.-.. . ..-.--. ...... .----.- .-..-- -. --- .--.--.-.-. ... - ..- ...-.-- -..--.----..");
for (int i = 0; i < 104; ++i )
for(int j=0;j<4;j++)
if((morsecode[j++] == morsearray[i++]))
a =((morsearray[i-4])/4);
char *ch =(char*)malloc(1*sizeof(char));
ch=azarray+a;
return ch;
}
函数keyread应该将莫尔斯字符串分成4个字符并将其传递给morse2english
应该找到莫尔斯电码的字母表示并将其返回给keyread函数并将其添加到的函数string4