#include
#include
char *weeks[]={"Monday","Tuesday","Wednesday","Thursday","Friday",
"Saturday","Sunday"};
char *trans[]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
void translate(char *pstr)
{
int i;
for(i=0;i<7;i++)
{
if(strcmp(weeks[i],pstr) == 0)
{
printf("%s中文意思为%s\n",weeks[i],trans[i]);
break;
}
}
}
int main()
{
char str[64];
printf("请输入要翻译的单词:");
scanf("%s",str);
translate(str);
return 0;
}
示例运行结果:
请输入要翻译的单词:Wednesday
Wednesday中文意思为星期三
#include
void main(){
char * weeks[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}
char * trans[7] ={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"}
printf("请输入要翻译的单词:");
char * temp;
scanf("%c",temp);
printf("\n");
printf("%c的中文意思为:%c",temp,trans[getThePostion(weeks,temp)])
}
int getThePostion(char **weeks,char *temp){
int i = -1;
for(i ; i < 7;i++){
if(*weeks[i] == *temp){
return i;
}
}
return i;
}