c - Comparing values of two arrays -
i have 2 arrays containing, each one, values of coordinates. in other words, first array contains values of x , second array contains values of y. goal consists of not having equal coordinates, means every coordinate must different others. tried this:
for (i=0; i<len(lrs)-1; i++) { (j=0; j<len(lrs) ; j++) { if ((pos.x[j]==pos.x[i+1])&&(pos.y[j]==pos.y[i+1])) printf("1"); } }
however, there's moment values of "j" , "i" same and, therefore, condition verified, not intended. maybe i'm not thinking right way, can't figure out.
it better make inner loop j > only:
for (i=0; i<len(lrs); i++) { (j=i+1; j<len(lrs) ; j++) { if ((pos.x[j]==pos.x[i])&&(pos.y[j]==pos.y[i])) printf("1"); } }
in case never check condition i==j. more on check each pair once.
Comments
Post a Comment