Advertisement

用C语言将整数翻译为英文,C语言实现翻译功能

阅读量:

本篇文章提供了一个具体的C语言实现翻译功能的实例,并向大家展示了一种高效的方法及其相关代码细节。具体内容包括完整的C语言代码示例以及详细的注释说明,请您在阅读过程中注意理解每一步骤的操作流程与实现原理。

#include

#define number 100

struct date

{

char chinese[30];

char English[30];

}a[number];

void copy(char *str1, char *str2, int counst)//将值赋给trans

{

int i = 0;

if (str2 == ' ' || str2 == '\0')

{

return;

}

while (counst--)

{

*str1++ = *str2++;

}

return;

}

int panduan(char *d, char *f)//判断是否相等

{

char *str1 = d, *str2 = f;

int xc=0;

while (!(xc = *str2 - *str1)&&*str1)

{

str1++;

str2++;

}

if (xc != 0)

{

return 0;

}

return 1;

}

char* ry( struct date a[number],char *wordtemp,int x)

{

for (int i = 0;i

{

if (panduan(a[i].English, wordtemp))

{

return a[i].chinese;

}

}

return "NULL";

}

int main()

{

char b;

int x;

int exit=0;

char str[50];

printf("[请先输入英文单词,再输入拼音,中间以空格隔开,当输入*时结束]\n");

for (int i=0;; i++)

{

printf("第[%d]组:\t", i+1);

scanf("%[^' ']", a[i].English);

scanf("%c", &b);

scanf("%[^\n]", a[i].chinese);

scanf("%c", &b);

if (a[i].English == ''&&a[i].chinese == '')

{

x = i;

break;

}

}

printf("[请输入你所要翻译的内容]\n");

scanf("%[^\n]", str);

printf("|翻译的结果为|:\n");

for (int i = 0;; i++)

{

if (str[i] != ' ')

{

char Trans[100];

int n = 0;

if(str[i]!=' ')

{

while (!(str[i] == ' ' || str[i] == '\0'))

{

n++;

i++;

if (str[i] == '\0')

{

exit = 1;

}

}

copy(Trans, &str[i - n], n);

Trans[n] = '\0';

printf("[%s]", ry(a,Trans,x));

}

if (exit)

{

break;

}

}

}

system("pause");

}

b73ae27b006561014fd9ef7d5423bf01.png

以下是我文章的主要内容。旨在帮助大家提升学习效果。也欢迎广学者和编程爱好者积极参与我们的社区活动。

全部评论 (0)

还没有任何评论哟~