首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C语言读写txt文件的有关问题

2012-07-16 
C语言读写txt文件的问题写了一个用C语言读写文件的程序,发现关闭文件的时候报了一个堆栈溢出的错误,系统为

C语言读写txt文件的问题
写了一个用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);

[解决办法]
xrayVideoPointsCorrespondence1=(double*)malloc(6*numPoints1);

请问下这句的释放在哪里?

还有 numPoints有初始化么?
[解决办法]
加断点,单步调试。指针再使用之前必须有指向的内存区域。使用完成后记得释放

热点排行