C语言中的莫尔斯电码译码器

C语言中的莫尔斯电码译码器,c,string,morse-code,C,String,Morse Code,我们本来应该把一个字符串翻译成摩尔斯电码,我已经用这个开关把这个问题解决了。每个字母都用空格分隔,但我不知道如何用斜杠(/)分隔单词。以下是我编写的代码: #include<stdio.h> #include<string.h> #include<conio.h> #include<process.h> #include<ctype.h> int main(){ char string[100], str1[100]; int len

我们本来应该把一个字符串翻译成摩尔斯电码,我已经用这个开关把这个问题解决了。每个字母都用空格分隔,但我不知道如何用斜杠(/)分隔单词。以下是我编写的代码:

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<process.h>
#include<ctype.h>

int main(){
char string[100], str1[100];
int length, i, j = 0;

printf("Enter sentence to convert: ");
gets(string);
length = strlen(string);

for (i = 0; i <= length; i++){
    switch(toupper(string[i])){
        case 'A':
            str1[j++]='.';
            str1[j++]='-';
            str1[j]=' ';
            break;

如果输入的字符串是一个句子,如何在单词之间添加斜杠?

每当看到空格(或空格序列?)时,请在输出字符串中附加
'/'

提示:如何识别一个单词的结尾和另一个单词的开头?当您看到这一点时,您希望输出斜杠。对吗?似乎不太可能需要包含process.h!(最好也不要使用conio.h。)那么我会将其包括在案例中吗?
        }
    j++;
}

str1[j - 1]='\0';
puts(str1);
system("pause");
return 0;
}