comparing 2D array element with 1D array element

I have a dynamic 2D array and I need to compare it to a static1D arrays elements, but my code doesn't work properly..
P.S this is just a part of my code, everything else works fine

1
2
3
4
5
6
7
row=0;
count=0;
do{
for(int i=0;i<n;i++)
if array[i][row] == arr2[i] count++;
}while(row!=n);
Well, neither row or n ever change, so, unless they are equal, that do ... while() loop will run ... for ever.

BTW, "my code doesn't work properly" isn't a terribly helpful statement of the problem. My car "doesn't work properly" either, but saying that to the garage isn't going to help them diagnose the issue.
Last edited on
do you really need count or do you just want a true/false equality comparison? I ask because I struggle to think of a use for knowing how many match when you don't know which ones matched; usually you want a list of the matches or mismatches from such a test. And if you just want true/false, a direct memory compare is better.

the double loop really makes no sense. The for loop is sufficient to check to see if a particular row is the same as the vector. You would only double loop if you wanted to check each row against the same vector, or, with some setup you don't have in place, to check several vectors against several rows or all the rows each are possible but you need more stuff for those.



Last edited on
Topic archived. No new replies allowed.