LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Double array and ArrayToFile(...)

Hi !
I have allocated the "ptr_matrix" - 2D array
by means of the malloc(...) function
and then inserted the "ptr_matrix" array
into ArrayToFile(...) function to save
to file "file.dat".
Unfortunately while the function
start occurs error ... Why ?


Below there are a snippet of my program:
=====================

double **ptr_matrix;

void main(void)
{

int k,i,l,n; // n-number o the rows, k-number of the columns

scanf ("%d%d", &n, &k);

ptr_matrix=malloc(n*sizeof(double *));

for(i=0; i *(ptr_matrix+i) = malloc(k*sizeof(double));

for(i=0; i for(l=0; l ptr_matrix[i][l] = 10.0;


// here occurs error when the program start

ArrayToFile ("file.dat", ptr_matrix, VA
L_DOUBLE, n*k, n,
VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_CONST_WIDTH,
10, VAL_ASCII, VAL_TRUNCATE);
}
0 Kudos
Message 1 of 2
(3,695 Views)
Hello kajpek,
The function ArrayToFile() is designed for use on a one dimensional array, not a multidimensional array. To put a matrix into a file, you will need to put the contents of the multidimensional array into a one dimensional array.

I have modified your code so that it works and placed it below:
"
/*********************************/
#include
#include
static int status;
double *ptr_matrix;

void main(void)
{

int k,i,l,n; // n-number o the rows, k-number of the columns

scanf ("%d%d", &n, &k);

ptr_matrix=malloc((n*k)*sizeof(double));

for(i=0; i<(n*k); i++)
ptr_matrix[i] = 10.0;

status = ArrayToFile ("file.dat", ptr_matrix, VAL_DOUBLE, (n*k), n,
VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS,
VAL_CONST_WIDTH, 10,
VAL_ASCII, VAL_TRUNCATE);

}
/*********************************/
"

Jeremiah Cox
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 2 of 2
(3,695 Views)