# Thread: comparing two arrays of floats

1. ## comparing two arrays of floats

I have two array of floats, each could have an undetermined amount of information. strcmp() didn't work and I ma guessing because it is not a string. I got memcmp() to work but I had to hard code the length I wanted to compare. How can I determine the length of each of the array of floats? Is there a better way of doing this then using memcmp()?

Thanks,

2. >>How can I determine the length of each of the array of floats?
Code:
```#define LEN(x) sizeof (x) / sizeof (x[0])
...
memcmp(a, b, LEN(a));```

3. I apoligize I am new and my terminology is a little vague.

Let's say the length is 10 I need to know many floats are actually in this array? (i.e. Maybe 5 or 7 or even 10)

Thanks again,

4. Could you try initializing all the elements in the array to a value you know that they'll never have? (I like to use the constants DBL_MIN and DBL_MAX if it is possible they can contain 0 or -1 or any other constant commonly used for errors.) Then you can see how many elements are not equal to the default value. A little time consuming, but it works....

Alternatively you can have a separate variable that stores the number of floats in the array. But everytime you add or delete elements you'll have to change the variable.

Is this what you're looking for?

5. if you use a storage class like vector you can just call the size() method. casey's idea works for fixed length arrays. For an unknown length dynamic array though, you're pretty much out of luck I think. Since this is the C++ forum though I'm going to suggest vector.

6. wait, you've allocated it to 10? well whatever you left in there could be seen as a float. If you initialize to zero for instance, there is a float in there. you need to keep a counter of some kind or use vector and let it do it for you.

7. Unless I find something else I will probably try initializing the elements to a number I know they won't have.