IDL FIX Equivalent

Hey, I was wondering if there was some sort of C++ equivalent for the IDL FIX function.

For example, say I want to find all the elements of FLOAT ARRAY1[] that are greater than NUM1 and convert them to INT ARRAY2[].

The problem I have with writing this code myself is not knowing how many elements are going to be greater than NUM1, so I don't know how to initialize ARRAY2[?].

Thank you.
Are you limited to arrays or can you use vectors? Each time a number is encountered in array1 that is greater than num1 you could just push it into a vector:

If not, you could do one of two things:

1. Make array2 the same size as array1 (which can potentially waste a metric fuck tonne lot of memory). You will want to keep an index of where the last element was entered into array2 (so you know where to put the next one as well as give an idea of how many elements are in the array),

2. Count the number of entries in array1 that are greater than num1 and dynamically allocate array2 to be that size then put the values in array2 (which would require two passes of array1).

There may be more (read better) ways, but I can't think of any off of the top of my head.

You will also want to look into casting:

Hope that helps

Vulgarity. My apologies.
Last edited on
Topic archived. No new replies allowed.