1. ## Comparing two arrays

I have an assigment that basically asks the program to read from a file "data.txt". This file has 50 values. So it is neccesary to make two arrays, the first one should take the first 25 values and the second array should take the remaining 25. Then compare them and give a result when the numbers are the same for the same suscript.

So it needs to read the same value at the same position for each array, that's where i get my problem :/

I get the following for the function (which is what i lack) in order to compare them:

Code:
```int equal_arrays(int a1 [], int a2 [], int n)
{
int i, result;
for (i=0; i<n; ++i)
if (a1[i] != a2[i]) result = 0;
else result = 1;

return (result);
}```
but.. I have no clue how to compare the arrays so it gives me the number of the one that repeats on both of them. I'm sure that what I've done so far is somewhere close to the end. I've been trying to make it work and think of alot of things but seems that none of them work. Any help would be really appreciated. Thanks in advance.

2. that comparing function is foolish. it returns 1 when the last elements is equal.
Code:
```// the correct one:
int equal_arrays(int a1 [], int a2 [], int n)
{
int i, result;
for (i=0; i<n; ++i)
if (a1[i] != a2[i])
return 0;
return (1);
}```
or you can simply use memcmp() to compare two arrays.

3. Originally Posted by RichSelian
that comparing function is foolish. it returns 1 when the last elements is equal.
or you can simply use memcmp() to compare two arrays.
Okay so I got the following from some reasearch i did. Not sure if its okay.

Code:
```#include <string.h>
....
int x[26], t[26];
....
result = memcmp (x,t,26);
if (result == 0)
printf ("%d",x);
return (0);
}```
never mind got it to work with the old code. I noticed that if I loop it for the result = 1 i can compare them until the loop is done. Will post the code in a while because it might need more work to do :/