# Thread: Need help with a functions/arrays.

1. ## Need help with a functions/arrays.

Somewhat a beginner, I'm trying to make a program that separates 50 integer numbers into two separate arrays(with 25 each naturally). I then need to make a function that takes the two numbers and if they are the same returns true, and false otherwise. I also need to find the cell number that they are located in so I made a pointer for that.

Here is the start of my function.

Code:
```int
find_same(int check1[], int check2[], int size, int*loc)
{
int i;
int same;
loc = 0;

for(i=0; i<size; ++i)
if(check1[i] == check2[i])
{
same = check1[i];
*loc = i;
}

return(same);

}```

Here is the rest of my program. I've comprehended it as got the numbers from the file, put them into two arrays and sent them to the function and then print the results. Am I missing anything?

Code:
```int
main (void)

{
int array1[25], array2[25], i, samenum, position;
FILE *input;

input = fopen("data.txt", "r");

for(i=0; i<25; ++i)
fscanf(input, "%d", &array1[i]);

for(i=1; i<25; ++i)
fscanf(input, "%d", &array2[i]);

printf("%d ", position);

fclose(input);

return(0);

}```

2. it looks like it would only print the last number that was the same and not all numbers that are the same. Is that what you wanted?

3. I want all the numbers that are the same e.g.

1st array 11 22 33 44 55 66 etc.
2nd array 43 96 33 23 52 66 etc.

Giving me 33,66.
Would I have to put it in a loop or if statement?

4. i guess it depend on your overall goal. You could just printf evertime you find an equivalent number inside the find_same() function. Or if you wanted to save it as data to acess later you could use another set of int arrays to save the number value and index location. Or You could use a two dimensional array as well using one index as the numbers value and the other as the the position index. There are other ways to do this as well.

Do you need to save the data for later?
Or is it just being printed on the screen for the users benifit?

if just for the user just format a table out of your already existing loop so the output could be like"
Code:
```Found     Value of Number       At index
1.          33                             2
2.          66                             5```

5. It's for the users benefit to display the number and the cell they are located in. The data does not need to be saved for later.

Would the printf just go in my if statement like this?

Code:
```   if(check1[i] == check2[i])
{
same = check1[i];
*loc = i;
printf("%d", same);
}```

6. Thats how i would do it and just label the columns before the loop so the user knew what number was what.

7. Alright I'll try it out and fiddle with it a little more, thanks.