what is the best way to compare int arrays b and c with a:
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
More information is needed on the question. I can divide your question in two ways as below,
Solution for Question no 1: One can use memcmp for this problem. Because memcmp will compare lexicographical and return 0 or 1 or -1 as below
#include
#include
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
#include
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
#include
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 no 2: One can use memcmp for this problem, the best solution for this problem is as below
Here, I answered for the above problem https://stackoverflow.com/a/36130812/5206646