怎么用c++编摩斯电码的翻译程序啊...求教!

来源:百度知道 编辑:UC知道 时间:2024/06/14 09:13:59
就是能把字母,数字,符号用“.”“-”互译的
以字母与字母之间隔一个空格,单词与单词之间隔三个空格的方式输入来翻译,求教,急!拜托大家了,快的话会有追加分数> <

输入摩斯电码 翻译出 英文,只能识别英文字母, 字母间隔一个空格,单词间隔三个空格 输入摩斯电码

#include "stdio.h"
#include "conio.h"
#include "string.h"

int morseindex(const char *a);

int main(void)
{
int i, j, space;
char *p;
char buffer[1024];
char a[6];

gets(buffer);

p = buffer;
i = 0;
space = 0;
while(1)
{
if (*p == 32 || *p == '\0')
{
a[i] = '\0';
if (strlen(a) != 0)
{
j = morseindex(a);
if (j >= 0)
printf("%c", 'a' + j);
}
i = 0;
space++;
if (space == 3)
printf(" ");
}
else
{
a[i++] = *p;
space = 0;
}
if (*p == '\0')
break;
p++;
}

}

int morseindex(const char *a)