Code: |
u16 Equals(array1, array2, length_of_both_arrays) { u16 comparison = 1; // true for(int i = 0; i < length_of_both_arrays, i++) if(array1[i] != array2[i]) comparison = 0; // false return comparison; // returns 1 for true, 0 for false } |
abilyk wrote: | ||
No, that's comparing the pointers of the two arrays. I assume from your question that you'd be comparing arrays that each have their own memory location, so that would always return false. Instead, you'll need to write a function that compares all the elements of the arrays.
Some pseudocode:
|
Code: |
for(int i = 0; i < arrayLength, ++i){ if(array1[i] != array2[i]){ return 0; } return 1; } |
col wrote: |
the above is functionally correct, but
if you shuffle it around a little it can be much more efficient: cheers col |
Quote: |
Heh, yeah, that is more efficient, isn't it? |
Code: |
for(int i = 0; i < arrayLength, ++i){ if(array1[i] != array2[i]){ return 0; } } return 1; |
tepples wrote: |
Would this be any more correct? |