fclose 失败,错误代码 Bad file number 是什么意思??

Ronal_Lee 2010-05-19 04:00:02
fclose 失败,错误代码 是 Bad file number ,请问这个错误代码 是什么意思,该怎么解决呢???
...全文
1355 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
十八道胡同 2010-05-19
  • 打赏
  • 举报
回复
int iRet = fclose(fp);
if(EOF == iRet)
{
//在这里出现的 errno = Bad file number 错误
}

你在用个变量吧,fp刚释放就有被利用
Ronal_Lee 2010-05-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 cattycat 的回复:]
你是linux还是,文件描述符号不对,看fopen是否错误了。
[/Quote]

我是windows,7楼贴出代码了,给看看这代码没问题吧???谢谢
Ronal_Lee 2010-05-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhzxlc_06 的回复:]
坏的文件数字..没有见过这种错误...是不是文件指针有问题?
楼主贴代码吧...
[/Quote]

void WriteLog(AnsiString sMessage, AnsiString _astrLogFileName)
{
try
{
AnsiString asFileName = ExtractFilePath(Application->ExeName)+ _astrLogFileName;

FILE *fp;
fp = fopen(asFileName.c_str(), "a+");
if (fp == NULL)
{
return;
}

AnsiString sRecord = "内容";

fprintf(fp, sRecord.c_str());
fprintf(fp, "\n");
long i = ftell(fp);

//大于9M就清空
if(i > 9216000)
{
fclose(fp);
fp = fopen(asFileName.c_str(),"wt");

if (fp == NULL)
{
return;
}
}

int iRet = fclose(fp);
if(EOF == iRet)
{
//在这里出现的 errno = Bad file number 错误
}
}
catch(Exception &E)
{
return;
}
catch(...)
{
return;
}
}
yellowtree12 2010-05-19
  • 打赏
  • 举报
回复
文件错误
cattycat 2010-05-19
  • 打赏
  • 举报
回复
你是linux还是,文件描述符号不对,看fopen是否错误了。
azure110 2010-05-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhao4zhong1 的回复:]
fclose(f);里面的f没有fopen,或已经不是之前fopen的返回值了。
[/Quote]

看看 你 f fopen 返回值会后面异常时的值是否相同,同时指针类的 东西最好用完后 把它设置为Null
白云飘飘飘 2010-05-19
  • 打赏
  • 举报
回复
文件号错误!
赵4老师 2010-05-19
  • 打赏
  • 举报
回复
fclose(f);里面的f没有fopen,或已经不是之前fopen的返回值了。
chaoliu1024 2010-05-19
  • 打赏
  • 举报
回复
坏的文件数字..没有见过这种错误...是不是文件指针有问题?
楼主贴代码吧...
You are visitor as of October 17, 1996.The Art of Assembly Language ProgrammingForward Why Would Anyone Learn This Stuff?1 What's Wrong With Assembly Language2 What's Right With Assembly Language?3 Organization of This Text and Pedagogical Concerns4 Obtaining Program Source Listings and Other Materials in This TextSection One: Machine OrganizationArt of Assembly Language: Chapter OneChapter One - Data Representation1.0 - Chapter Overview1.1 - Numbering Systems1.1.1 - A Review of the Decimal System1.1.2 - The Binary Numbering System1.1.3 - Binary Formats1.2 - Data Organization1.2.1 - Bits1.2.2 - Nibbles1.2.3 - Bytes1.2.4 - Words1.2.5 - Double Words1.3 - The Hexadecimal Numbering System1.4 - Arithmetic Operations on Binary and Hexadecimal Numbers1.5 - Logical Operations on Bits1.6 - Logical Operations on Binary Numbers and Bit Strings1.7 - Signed and Unsigned Numbers1.8 - Sign and Zero Extension1.9 - Shifts and Rotates1.10 - Bit Fields and Packed Data1.11 - The ASCII Character Set1.12 Summary1.13 Laboratory Exercises1.13.1 Installing the Software1.13.2 Data Conversion Exercises1.13.3 Logical Operations Exercises1.13.4 Sign and Zero Extension Exercises1.13.5 Packed Data Exercises1.14 Questions1.15 Programming ProjectsChapter Two - Boolean Algebra2.0 - Chapter Overview2.1 - Boolean Algebra2.2 - Boolean Functions and Truth Tables2.3 - Algebraic Manipulation of Boolean Expressions2.4 - Canonical Forms2.5 - Simplification of Boolean Functions2.6 - What Does This Have To Do With Computers, Anyway?2.6.1 - Correspondence Between Electronic Circuits and Boolean Functions2.6.2 - Combinatorial Circuits2.6.3 - Sequential and Clocked Logic2.7 - Okay, What Does It Have To Do With Programming, Then?2.8 - Generic Boolean Functions2.9 Laboratory Exercises<

64,639

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧