我被賦予了這個任務,這是我到目前爲止編寫的代碼。此代碼只接受一個字母時,它應該做的不是字母比較多,所以我可以在一個字類型,這將是在莫爾斯電碼c編程scanf
#include "stdafx.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
int _tmain(int argc, _TCHAR* argv[])
{
char input[80], str1[100];
fflush(stdin);
printf("Enter a phrase to be translated:\n");
scanf("%c", &input);
int j = 0;
for (int i = 0; i <= strlen(input); i++)
{
str1[j] = '\0';
switch(toupper(input[i]))
{
..................
}
j++;
}
printf("\nMorse is \n %s\n", str1);
fflush(stdout);
//printf("%s\n ",morse);
free(morse);
}
@尼古拉:參考:HTTP://meta.stackexchange .com/questions/147100/the-homework-tag-is-now-official-deprecated – Default
您將分配給莫爾斯字符串的小內存!爲什麼不聲明和初始化它作爲一個數組,如'char morse [] =「...」;' –
首先,請標記作業問題。然後,提示 - 通過ASCII碼索引的靜態表,將字符映射到莫爾斯碼字符串。 –