Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C语言中两个数组元素的比较_C - Fatal编程技术网

C语言中两个数组元素的比较

C语言中两个数组元素的比较,c,C,我想比较数组中的一个元素和数组中的第二个元素“hello”字。如果i值得到第一个元素x[i]和y[i],它们将返回正确的结果,但如果它们在第一个位置不相同,则不会返回任何结果。myreturn函数比较两个字符串并返回相同的字符串。我哪里出了问题 char myreturn (char x[],char y[]) { if (strcmp(x,y)==0) printf("%s ",x); else return 0; } main() {

我想比较数组中的一个元素和数组中的第二个元素“hello”字。如果i值得到第一个元素x[i]和y[i],它们将返回正确的结果,但如果它们在第一个位置不相同,则不会返回任何结果。myreturn函数比较两个字符串并返回相同的字符串。我哪里出了问题

char myreturn  (char x[],char y[])
{
    if (strcmp(x,y)==0)
        printf("%s ",x);
    else
        return 0;
}

main()
{
    char x[10][10]={"hello","super","everything"};
    char y[10][10]={"hero", "mind" ,"hello"};
    int i;
    for (i=0; i<3; i++)
        if x[i] || y[j] != '\0')
        {
            i++;
        }
        else if (x[i] || y[j]=='\0')
        {
            myreturn(x[i],y[j]);
        }
}
char myreturn(char x[],char y[]
{
if(strcmp(x,y)==0)
printf(“%s”,x);
其他的
返回0;
}
main()
{
char x[10][10]={“你好”,“超级”,“一切”};
chary[10][10]={“英雄”,“心灵”,“你好”};
int i;
对于(i=0;i要修正的样本

#include <stdio.h>
#include <string.h>

int main(void){
    char x[10][16]={"hello","super","everything"};
    char y[10][16]={"hero", "mind" ,"hello"};
    int i, j;
    for (i=0; i<10; i++){
        for(j=0; j<10; j++){
            if(*x[i] && *y[j] && strcmp(x[i], y[j])==0)
                printf("'%s' exist x[%d] and y[%d]\n", x[i], i, j);//'hello' exist x[0] and y[2]
        }
    }
    return 0;
}
#包括
#包括
内部主(空){
char x[10][16]={“你好”,“超级”,“一切”};
chary[10][16]={“英雄”,“心灵”,“你好”};
int i,j;

对于(i=0;i@SouravGhosh:你知道吗?你的
所有的
字符串都是溢出的,因为你没有为
'\0'
@sohel k预留空间。至于我,我什么都不懂。你想做什么?!替换
字符myreturn(char x[],char y[])
->
无效myreturn(char x[],char y[])
返回0;
->
返回;
您使用x[i]| | y[j],但无论是定义的还是增加/减少的,我都找不到“j”