gpt4 book ai didi

c - C语言的摩尔斯电码翻译器

转载 作者:太空宇宙 更新时间:2023-11-04 02:51:53 27 4
gpt4 key购买 nike

我们应该将字符串翻译成摩尔斯电码,而我已经使用 switch 实现了这一点。每个字母都用空格分隔,但我不知道如何用斜杠 (/) 分隔单词。这是我编写的代码:

#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;

直到 Z 然后...

        }
j++;
}

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

如果输入的字符串是一个句子,如何添加斜杠来分隔单词?

最佳答案

每当您看到一个空格(或一系列空格?)时,将 '/' 附加到输出字符串。

关于c - C语言的摩尔斯电码翻译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21323492/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com