So I have a double array, where I'm inputting float numbers to certain points in an array. Sometimes, the numbers that are printed out are completely different from what I put in.
Here is the part of the code:
Code:
.
.
.
while( token != NULL )
{
num = atof(token);
test[j][i] = num;
printf( " \n%s, i is %d, j is %d\n", token,i,j );
printf( "number is %f \n value test of i,j is %f\n",num, test[i][j]);
token = strtok(NULL, ",");
i++;
}
buffer[0] = 0; n = 0; i = 0; j++;
.
.
.
The test array is [8][17]
The printouts are like so:
0, i is 0, j is 0
number is 0.000000
value test of i,j is 0.000000
0, i is 1, j is 0
number is 0.000000
value test of i,j is 0.000000
0, i is 2, j is 0
number is 0.000000
value test of i,j is 0.000000
0, i is 3, j is 0
number is 0.000000
value test of i,j is 2985268883875948100000000000000000.000000
If someone could tell my why the float num prints out fine, but when put into an array becomes garbage?
I'm taking string values from a csv file and turning them into floats, but no problems seem to crop up there.
I reset i when appropriate and increment j when needed, so I don't think my problems are from incorrect array values (though they might be)
Thanks.