求助(急,在线等)
有一段程序,原来是用x,y坐标输入,然后用另一个function计算距离,现在我想直接读入距离的二维数组,不知如何改?
本人初学,望高手指点,帮助改一下,谢谢!
void input_pbm(int nc,struct node *t,int **ti,FILE *ifp,FILE *ofp)
{ float *x,*y; /*The x,y coordinates */
int i; /*Index.*/
x = (float *)calloc(nc,sizeof(float));
y= (float *) calloc (nc,sizeof(float));
for(i=0;i<nc;++i){ /*input data from the input file, */
fscanf(ifp,"%f",&x[i]);
fscanf(ifp,"%f",&y[i]);
} /*end for*/
convxy(nc,x, y, ti, ofp);
free(x);
free(y);
return;
}/*end input_pbm function*/
void convxy(int nc,float *x, float *y, int **ti, FILE *ofp)
{ int i, j; /* Indices. */
double dx, dy; /* The difference between x and y coordinates.*/
double power(); /* The power function */
for (i=0; i< nc; ++i) /* Computation. */
for (j=i+1; j< nc; ++j) {
dx = x[i] - x[j];
dy = y[i] - y[j];
ti[i][j] = sqrt(dx*dx + dy*dy);
ti[j][i] = ti[i][j];
} /* end for j*/
}/*end for i*/
} /*End convxy*/