【发布时间】:2011-08-03 14:09:09
【问题描述】:
我正在尝试运行一些代码,但 fflush() 出现错误:
Invalid file descriptor. File possibly closed by a different thread
以下是代码的相关部分:
fhandle = fopen("dbfile.bin", "rbc");
/* There is a valid dbfile.bin file - get file size */
_fstat(_fileno(fhandle), &file_stat);
printf("dbfile.bin size = %d\n", file_stat.st_size);
g_tpd_list = (tpd_list*)calloc(1, file_stat.st_size);
if (!g_tpd_list)
{
rc = MEMORY_ERROR;
}
else
{
fread(g_tpd_list, file_stat.st_size, 1, fhandle);
fflush(fhandle);
fclose(fhandle);
}
【问题讨论】:
-
通常你会在写入文件时刷新文件(以清除写入缓冲区)......你不应该因为你正在做的事情而刷新它,有什么影响你期待吗?
-
我什么都不期待。这部分代码由讲师按原样提供。
标签: c visual-c++ stream filehandle fflush