int main(){
int f,d;
float** a1, **a2,**p,**t;
read_from_file(a1,a2);
/*DEBUG PRINT AGAIN MATRIX A1 */
for(f = 0; f<4; f++)
for(d = 0; d<4; d++)
printf("a[%d][%d] = %f\n",f,d,a1[f][d]);
}
void read_from_file(float** a, float** b){
a = my_malloc(4,4);
b = my_malloc(4,4);
int temp;
FILE* fd;
fd = fopen("matrici.txt","r");
if(fd == NULL){
perror("errore opening file\n");
exit(1);
}
int i,j;
for(i=0; i<4; i++)
for(j=0; j<4; j++){
fscanf(fd,"%d", &temp);
a[i][j]= (float)temp;
}
for(i=0; i<4; i++)
for(j=0; j<4; j++){
fscanf(fd,"%d", &temp);
b[i][j]= (float)temp;
}
fclose(fd);
/* DEBUG PRINT MATRIX "A1" */
for(i = 0; i<4; i++)
for(j = 0; j<4; j++)
printf("a[%d][%d] = %f\n",i,j,a[i][j]);
}
ok hello everybody, while i was coding a program that should had to read from file some floating values and store them into that matrix, an inusual bug occurred: when i print my matrix in the function " read from file" the values stored in it are:
a[0][0] = 3.000000
a[0][1] = 1.000000
a[0][2] = -1.000000
a[0][3] = 0.000000
a[1][0] = 0.000000
a[1][1] = 7.000000
a[1][2] = -3.000000
a[1][3] = 0.000000
a[2][0] = 0.000000
a[2][1] = -3.000000
a[2][2] = 9.000000
a[2][3] = -2.000000
a[3][0] = 0.000000
a[3][1] = 0.000000
a[3][2] = 4.000000
a[3][3] = -10.000000
but when i print again the same matrix in the main function ( after the calling of read_from_file) the values stored in it are:
a[0][0] = 53806348.000000
a[0][1] = 14144784983268524032.000000
a[0][2] = 208613343232.000000
a[0][3] = 15659650322576441344.000000
a[1][0] = 13841544192.000000
a[1][1] = 0.048908
a[1][2] = 71857615689329949954782789632.000000
a[1][3] = 202218044416841482240.000000
a[2][0] = 3664429973504.000000
a[2][1] = 15151608880334635008.000000
a[2][2] = 234149008.000000
a[2][3] = 55906620.000000
a[3][0] = 14358698268987228160.000000
a[3][1] = 3157.142334
a[3][2] = 15151608880334635008.000000
a[3][3] = 13.265934
thanks for the help :)