Hello,
I am trying to pass a float array from a funtion. I wrote an test program to get the idea first. At first, I tried loading numbers from a file, but some were returned wrong. So I tried assigning numbers to the matrix (as in the following code) and still one came out wrong (matrix[0][1]). Does someone know where is my mistake?
Thanks
The main() file
#include <stdio.h>
#include <stdlib.h>
void load (char *data, float (*matrix)[1]);
main()
{
char data[] = "data.txt";
FILE *input;
float matrix[1][1];
int i,j;
load(data, matrix);
for (i = 0; i<=1; i++)
{
for(j = 0; j<=1; j++)
printf("%f ",matrix[j][i]);
printf("\n");
}
printf("\n");
return 0;
}
And the function:
#include <stdio.h>
#include <stdlib.h>
void load(char *data, float (*matrix)[1])
{
FILE *input;
matrix[0][0] = 1.00;
matrix[0][1] = 4.2;
matrix[1][0] = 10.28;
matrix[1][1] = 9.87;
return;
}
I supposed the output should be
1.000000 4.200000
10.280000 9.870000
But it actually is:
1.000000 10.280000
10.280000 9.870000