C语言读写txt文件的问题
C_arm 2012-06-29 10:03:41 写了一个用C语言读写文件的程序,发现关闭文件的时候报了一个堆栈溢出的错误,系统为windowsXP,编译器是VS2008,代码如下:
FILE* inputXrayPoints1;
int numPoints1;
double* xrayVideoPointsCorrespondence1;
int iterPoints;
double xrayPointX;
double xrayPointY;
double videoPointX;
double videoPointY;
int point3DX;
int point3DY;
inputXrayPoints1=fopen("testCase/pointsCorrespondence1.txt","r");
fscanf(inputXrayPoints1,"%d",&numPoints1);
//fprintf(stdout,"numPoints1:\t%d\n",numPoints1);
xrayVideoPointsCorrespondence1=(double*)malloc(6*numPoints1);
for(iterPoints=0;iterPoints<numPoints1;++iterPoints){
fscanf(inputXrayPoints1,"%lf%lf%lf%lf%d%d",&xrayPointX,&xrayPointY,&videoPointX,&videoPointY,&point3DX,&point3DY);
xrayVideoPointsCorrespondence1[6*iterPoints]=xrayPointX;
xrayVideoPointsCorrespondence1[6*iterPoints+1]=xrayPointY;
xrayVideoPointsCorrespondence1[6*iterPoints+2]=videoPointX;
xrayVideoPointsCorrespondence1[6*iterPoints+3]=videoPointY;
xrayVideoPointsCorrespondence1[6*iterPoints+4]=(double)point3DX;
xrayVideoPointsCorrespondence1[6*iterPoints+5]=(double)point3DY;
fprintf(stdout,"Point:\t%d\n%lf\t%lf\t%lf\t%lf\t%d\t%d\n",iterPoints,xrayPointX,xrayPointY,videoPointX,videoPointY,point3DX,point3DY);
}
fclose(inputXrayPoints1);