Best way to compare two int arrays of the same length?

What is the best way to compare int arrays b and c with:

int a[] = {0,1,0,0,1};
int b[] = {0,1,0,0,1};
int c[] = {1,1,0,0,1};

b and c are just examples, suppose they can be any combination of 0s and 1s.

I am trying to detect arrays identical to a. I searched for this for a while and did not find a satisfactory answer.

This is a newbie question, which I understand, thank you for your patience.

+5
source share
4 answers

Use the standard function memcmpfrom <string.h>.

memcmp(a, b, sizeof(a)) == 0

when aand bequal.

+18
source

If you mean

int a[] = {0,1,0,0,1};
int b[] = {0,1,0,0,1};
int c[] = {1,1,0,0,1};

then

memcmp(a, b, sizeof(a)); /* returns zero for a match */
memcmp(a, c, sizeof(a)); /* returns nonzero for no match */
+5
source

.

+4

..! , ,

  • ?? Ex: char a [] = {a, b, c}, b [] = {a, c, b} , ur , , a!= b

  1. ? Ex: char a [] = {a, b, c}, b [] = {a, c, b} , ur , , == b

№ 1: memcmp . memcomp 0 1 -1,

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

        char a[]={'a','b','c'};
        char b[]={'a','b','c'};
        int x=memcmp(a,b,sizeof(a));
        printf("%d\n",x);

    return 0;
    }
***output:0***

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

        char a[]={'a','c','b'};
        char b[]={'a','b','c'};
        int x=memcmp(a,b,sizeof(a));
        printf("%d\n",x);

    return 0;
    }
***output:1***

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

        char a[]={'a','b','c'};
        char b[]={''b,'a','c'};
        int x=memcmp(a,b,sizeof(a));
        printf("%d\n",x);

    return 0;
    }
***output:-1***

Solution for question number 2: you can use memcmp for this problem, the best solution for this problem is below

here I answered for the above problem fooobar.com/questions/1101548 / ...

0
source

All Articles