LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a two dimensional array of char

Hi,

I have in one dll a function that writes data into an array it receives by ref.
function1(char BarCode[10][16])
{
}

When I call this procedure from a different dll, must I pass the same array?

function2()
{
char myArr[10][16];
function1(myArr);
}

1) It works like that by I still would like to know if this is the best way to do it, or, whether there is a better way.
2) Must specify the array size? Is there a way that function1 receives the pointer of the array without knowing its size?
3) If this is the way to do it, how do I specify it when I create a function panel?

Thanks
Rafi
0 Kudos
Message 1 of 3
(3,609 Views)
When declaring an array as a formal parameter for a function, you need to specify the number of columns, but you don't need to specify the number of rows. In a database analogy, you need to specify the record length, but not the number of records.
To make your function1 more general, rather than declaring the rows and columns of the array, declare only the the columns and pass the number of rows as a separate parameter. For example:
void function1(char BarCode[][RECORDLENGTH], int records)
{
//...
}

To take the next step toward generalizing the function, pass three parameters to the function: a pointer to the array, the number of rows, and the number of columns. For example:
void function1(char *pBarCode, int rows, int recordlength)
{
//...
}

Passing an array pointer works with a function panel. See the attached example, which includes function panels and functions for passing arrays and using array subscripts and functions for passing an array pointer and doing some pointer arithmetic to get to the array elements.
Message 2 of 3
(3,592 Views)
Thanks Al,

Good answer and nice example...

Thanks again
Rafi
0 Kudos
Message 3 of 3
(3,565 Views)