文件异常(Expression: *file!=_T('\0');)
来源:百度文库 编辑:神马文学网 时间:2024/05/17 16:01:29
现在一个文a.txt.我的程序会对a.txt的属性进行修改.而网页会对这个文件的属性进行读操作.我使用了CFileStatus类.但有时程序会当掉.提示为fopen.c 54行出错Expression: *file!=_T( '\0 ');问题出在哪? That means that the fopen failed (file handle is NULL) . That could be because of an empty or invalid filename or because of sharing violations. Check the lhandle value in writelog() and try to write the error you got :
#include
#inlude
#include
void writelog(int key,char *file)
{
FILE *lhandle;
lhandle = fopen(file, "a+ ");
if (lhandle == NULL)
{
ofstream ofs( "c:\\keyboard.err ", ios::append | ios::out);
if (!ofs.fail())
{
ofs < < "filename = " < < filename < < " open error = " < < errno < < endl;
ofs.close();
return;
}
}
....
#include
#inlude
#include
void writelog(int key,char *file)
{
FILE *lhandle;
lhandle = fopen(file, "a+ ");
if (lhandle == NULL)
{
ofstream ofs( "c:\\keyboard.err ", ios::append | ios::out);
if (!ofs.fail())
{
ofs < < "filename = " < < filename < < " open error = " < < errno < < endl;
ofs.close();
return;
}
}
....