gpt4 book ai didi

c - 检查两个单词是否彼此相等?(C)

转载 作者:行者123 更新时间:2023-11-30 19:36:26 25 4
gpt4 key购买 nike

你好。我想制作一本简单的英语-土耳其语词典。这是我的作业。我必须用 C 编写代码,但我根本不懂 C。为什么我的以下代码不起作用?

#include<stdio.h>
int main()
{
int i;

char word_array[10][20] ={"araba","car","kalem","pencil","derin","deep","mavi","blue","el","hand" };
//char arama[5] = {'d','e','r','i','n'};
char search[10] = "araba ";


for(i = 0 ; i < 10; i=i+2){
if(word_array[i] == search){
printf("i found: %s\n",i);
}
else{
printf("The word isnt in the array. %s\n",word_array[i],search);
}
}

return 0;
}

最佳答案

查看下面的代码。它修复了您的代码的一些问题。

    #include<stdio.h>
#include <string.h>
int main()
{
int i;

char word_array[10][20] ={"araba","car","kalem","pencil","derin","deep","mavi","blue","el","hand" };
char search[10] = "araba";


for(i = 0 ; i < 10; i++){
if(strcmp(word_array[i],search) == 0){
printf("i found: %s\n",i);
break;
}
}

if(i>=10) {
printf("The word %s isnt in the array.\n",search);
}

return 0;
}

关于c - 检查两个单词是否彼此相等?(C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40752731/

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