Click here to Skip to main content
13,346,397 members (64,657 online)
Rate this:
Please Sign up or sign in to vote.
See more:
how do i compare characters of two arrays before adding elements from one of the arrays into the other, inorder to ensure that if the characters already exist in the destination array, then that character should not be copied into it?
Posted 19-Nov-12 5:41am
Updated 19-Nov-12 23:05pm
Nelek 19-Nov-12 11:21am
What type of data are you actually speaking about? How about the length of the arrays / volumen of data?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As far as the arrays are not too long and that the type of data can be compared with == operator

You can use two for loops one nested into the another one. Actually the same operation than going through a 2-dimensional array[i][j]

bool error = false;
for (int i=0; i < length_a; i++)
   for (int j=0; j < length_b; j++)
      if (array_a[i]== array[b] array_b[j])
         error = true;

if (error == false)
   // No match found, do whatever you need to

[edit] array[b] corrected to array_b[j] [/edit]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100