读取两行 double 数字:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0.02 0.12 0.12 0.1 0.18 0.2 0.24 0.32 0.26 0.18 0.14 0.04 0.04 0.02 0.02 0 0 0 0 0 0 0 0 0 0 0 0 0 0
代码:
ptr=strtok(line," ");
if(ptr == NULL)
continue;
while(ptr != NULL) {
num = strtod(ptr,NULL);
kd_ljj.x[row][col]=num;
printf("row=%d col=%d num=%lf\n",row,col,num);
row++;
ptr=strtok(NULL," ");
}
读取完成后,为啥用 gdb 看到的是这样的:
(gdb) p kd_ljj.x
$1 = {{0, 0} <repeats 11 times>, {0, 0.02}, {0, 0.12}, {0, 0.12}, {0,
0.10000000000000001}, {0, 0.17999999999999999}, {0, 0.20000000000000001}, {0,
0.23999999999999999}, {0, 0.32000000000000001}, {0, 0.26000000000000001}, {0, 0.17999999999999999}, {0,
0.14000000000000001}, {0, 0.040000000000000001}, {0, 0.040000000000000001}, {0, 0.02},
{0, 0.02}, {0,
0} <repeats 14 times>}
为什么中间的数字会出现偏差,而 printf 打印的又是正常的,这个是代码的问题还是什么原因