Windows fopen在eclipse cdt中调试时失败
请查看以下代码段:Windows fopen在eclipse cdt中调试时失败,windows,eclipse,debugging,mingw,eclipse-cdt,Windows,Eclipse,Debugging,Mingw,Eclipse Cdt,请查看以下代码段: #include <stdio.h> int main () { FILE * pFile; pFile = fopen ("c:\\Temp\\test.txt","rb"); if (pFile!=NULL) { printf("opened\n"); fclose (pFile); } else{ printf("error\n"); } return 0; } 编译器设置: -O0 -g3 -Wall -c -fmessage-leng
#include <stdio.h>
int main ()
{
FILE * pFile;
pFile = fopen ("c:\\Temp\\test.txt","rb");
if (pFile!=NULL)
{
printf("opened\n");
fclose (pFile);
}
else{
printf("error\n");
}
return 0;
}
编译器设置:
-O0 -g3 -Wall -c -fmessage-length=0
如果我启动调试器并一步一步地执行每条指令直到fopen(..),有人知道fopen失败的原因吗
我期待着你的回答。非常感谢。我已经解决了这个问题 在fopen调用之前,我执行了以下代码:
char* ptr = NULL;
int size = 1024;
ptr = malloc(sizeof(size));
memset(ptr, 0, size);
fopen("binary.txt", "rt");
问题是,虽然只分配了sizeof(size)字节,但memset应用于1024字节。
由于先前对1024字节使用的memset调用导致堆内存损坏,因此随后的fopen调用被取消
谢谢你
-O0 -g3 -Wall -c -fmessage-length=0
char* ptr = NULL;
int size = 1024;
ptr = malloc(sizeof(size));
memset(ptr, 0, size);
fopen("binary.txt", "rt");