Thread: Comparing two arrays

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    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.
    Last edited by Gonz; 03-23-2011 at 01:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparing string arrays
    By never_lose in forum C Programming
    Replies: 17
    Last Post: 03-20-2011, 01:38 AM
  2. Comparing elements of character pointer arrays
    By axe in forum C Programming
    Replies: 2
    Last Post: 11-14-2007, 12:20 AM
  3. Comparing Arrays
    By Raison in forum C++ Programming
    Replies: 10
    Last Post: 04-20-2004, 02:21 PM
  4. comparing character arrays
    By Neildadon in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2003, 05:29 AM
  5. Comparing Character Arrays
    By LostNotFound in forum C++ Programming
    Replies: 2
    Last Post: 02-23-2003, 12:42 PM