#include <stdio.h>
#include <string.h>
// 定义单词和翻译的结构体
typedef struct {
char english[50];
char chinese[50];
} WordTranslation;
int main() {
WordTranslation translations[] = {
{“apple”, “苹果”},
{“banana”, “香蕉”},
{“orange”, “橙子”},
{“dog”, “狗”},
{“cat”, “猫”}
};
int numTranslations = sizeof(translations) / sizeof(WordTranslation);
char inputWord[50];
printf("请输入要翻译的单词: ");
scanf("%s", inputWord);
int found = 0;
for (int i = 0; i < numTranslations; i++) {
if (strcmp(inputWord, translations[i].english) == 0) {
printf("%s 的翻译是: %s\n", inputWord, translations[i].chinese);
found = 1;
break;
}
}
if (!found) {
printf("未找到 %s 的翻译\n", inputWord);
}
return 0;
}