LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass a 2D array in CVI and reference if in a function?

I am trying to write a function that selects values out of a 2D array.  I want to pass the array and then reference it later.  I have tried several ways the last being:

float table[10][10];

bool function(float *array);

main
{
     //Do work

    function(table);

    return;
}

bool function(float *array)
{
    float number = array[3][4];

    if (number > 0)
        return true;
    else
       return false;
}

I am used to programming in the c++ world but, this project requires I use cvi any suggestions?




0 Kudos
Message 1 of 6
(4,934 Views)

You could always prototype it as: 

bool function (float [10] [10]);

 That way the compiler knows all it needs to, to successfully access the desired components.

JR

0 Kudos
Message 2 of 6
(4,918 Views)
Hi, you can find in this thread some useful informations about creating and using 2d arrays and functions that manipulates those arrays.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 6
(4,910 Views)
I have done that in the past but, in this case I have arrays of different sizes being passed into the same function. 

I forgot to add in my last post that when I use the above code I get an error of:

  572, 44  Type error: pointer expected.


0 Kudos
Message 4 of 6
(4,908 Views)
Thanks Roberto. 

Now, that you mention it that does seem like the right way to do it.  Should have thought of that before.


0 Kudos
Message 5 of 6
(4,906 Views)

Additionally, bool is not a type in C (and true and false are not built in constants); you could do something like

typedef int bool;

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

if you want. This is a fairly common idiom. Frequently, people use boolean instead of bool (mainly so the code will compile in C and C++ compilers).

Adding this along with changing the function prototype to

bool function (float array[10][10]);

in both places will make this code compile.

Hope this helps,

-alex

0 Kudos
Message 6 of 6
(4,904 Views)