09-27-2005 10:02 AM
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?
09-27-2005 10:29 AM
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
09-27-2005 10:41 AM
09-27-2005 10:44 AM
09-27-2005 10:46 AM
09-27-2005 10:47 AM
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