|  | 
 
| 
#include <stdio.h>
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  
 double **array2DI(int col, int row)
 {
 double **dst;
 int i;
 dst = (double**)malloc(sizeof(double*)*col);
 dst[0] = (double*)malloc(sizeof(double)*row*col);
 for (i = 1; i<col; i++)
 dst[i] = dst[i - 1] + row;
 return dst;
 }
 void arrayFree2DI(double **array)
 {
 if (array != NULL)
 {
 free(array[0]);
 free(array);
 array = NULL;
 }
 return;
 }
 
 void main()
 {
 int width = 30;
 int height = 20;
 double **joint=array2DI(width, height);
 FILE *fpRead = fopen("BJ.txt", "r");
 if (fpRead == NULL)
 {
 return 0;
 }
 for (int y = 0; y < height; y++) {
 for (int x = 0; x < width; x++) {
 fscanf(fpRead, "%lf ", &joint[y][x]);
 if (y == 10)
 {
 printf("joint[%d][%d]=%4f\n", y + 1, x + 1, joint[y][x]);
 }
 }
 }printf("\n");
 
 for (int x = 0; x < width; x++) {
 printf("joint[11][%d]=%4f\n", x + 1, joint[10][x]);
 }printf("\n");
 
 
 printf("\n");
 fclose(fpRead);
 arrayFree2DI(joint);
 }
 
 环境是VS2013,结果如图
 C:\Users\lenovo\Desktop
 我的数组矩阵中第11行的数字,为什么两次printf的结果不一样??
 我首先定义了一个二维的动态数组,然后用动态数组去读取txt文件中的数字,一共是30*20个,读取的时候,我用了printf,显示的数字是对的,全部读取完毕后,我又用printf显示了某一行,发现和txt中数字有出入
 | 
 |