问题描述
在0x102e1cee(msvcr100d.dll)的文件名.exe 0000005未处理的异常:在访问冲突写入位置0x00416858。
调试点行:
如果(_putc_nolock(CH,F)== EOF)
code的
的#else / * _UNI code * /
如果(_putc_nolock(CH,F)== EOF)
#ENDIF / * _UNI code * /
* pnumwritten = -1;
其他
++(* pnumwritten);
}
在output.c我相信在Visual Studio库被链接。我没有联系起来。
我的code是:
身体=
myFile=CreateFile(\"Sample.txt\",FILE_APPEND_DATA,FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
BufferNo = sprintf的(身体,%。5F%[3] .5f%[3] .5f%[3] .5f%[3] .5f%[3] .5f%[3] .5f%[3] .5f \\ N,A1,A2,A3,A4,A5,A6,A7,A8);
WriteFile的(MYFILE,身体,lstrlen(体),0,NULL);
CloseHandle的(MYFILE);
我最初写了下面几行到文件。我不得不写的标题。
HANDLE MYFILE =的CreateFile(Sample.txt的,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0);
字符* HeadingStr =A1 A2 A3 A4 A5 A6 A7 A8 \\ N的;
WriteFile的(MYFILE,HeadingStr,lstrlen(HeadingStr),0,NULL);
CloseHandle的(MYFILE);
我要如何解决这个问题?注意:我有写权限。我作为管理员,太。
请注意,我已经定义BufferNo,MYFILE,近code使用之外。
更新
我删除身体=
现在,我得到
文件名.exe触发一个断点。
指着下面的评论中提到的文件。
**编辑**
现在,我有问题的写作。
错误读取
未处理的异常:0000005:在访问冲突写入位置00000000。
和点到线
WriteFile的(MYFILE,身体,lstrlen(体),0,NULL);
变量体
在本节不正确。
身体=;
...
BufferNo = sprintf的(身体,%。5F%[3] .5f%[3] .5f%[3] .5f%[3] .5f%[3] .5f%[3] .5f%[3] .5f \\ n
A1,A2,A3,A4,A5,A6,A7,A8);
presumably这是一个的char *
(alhtough我只是猜测),这意味着您要一堆数量的值写入能够在常量字符串持有恰好为零字符。因为它是一个常量,它是不可写的。
将其更改为字符体[1000];
或类似的东西。
Unhandled exception at 0x102e1cee (msvcr100d.dll) in filename.exe 0xC0000005: Access violation writing location 0x00416858 on.
The debugging points to line:
if (_putc_nolock(ch, f) == EOF)
of code
#else /* _UNICODE */
if (_putc_nolock(ch, f) == EOF)
#endif /* _UNICODE */
*pnumwritten = -1;
else
++(*pnumwritten);
}
in output.c which I believe is linked in visual studio library. I did not link it.
My code is:
body=""
myFile=CreateFile("Sample.txt",FILE_APPEND_DATA,FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
BufferNo=sprintf(body,"%.5f %[3].5f %[3].5f %[3].5f %[3].5f %[3].5f %[3].5f %[3].5f \n",a1,a2,a3,a4,a5,a6,a7,a8);
WriteFile(myFile,body,lstrlen(body),0,NULL);
CloseHandle(myFile);
I initially wrote to file with following lines. I had to write the heading.
HANDLE myFile=CreateFile("Sample.txt",GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0);
char* HeadingStr="a1 a2 a3 a4 a5 a6 a7 a8 \n";
WriteFile(myFile,HeadingStr,lstrlen(HeadingStr),0,NULL);
CloseHandle(myFile);
How do I solve this error? Note I have write permission. I ran as administrator, too.Note that I have already defined BufferNo, myFile, outside the use in last code.
UPDATEI removed body=""
Now I get
filename.exe triggered a breakpoint.
pointing to the file mentioned in comment below.
**EDIT**
Now, I have problem writing.Error reads
Unhandled exception at 0x7c811384 in stabilo.exe: 0xC0000005: Access violation writing location 0x00000000 on.
and points to line
WriteFile(myFile,body,lstrlen(body),0,NULL);
The variable body
in this section is incorrect.
body="";
...
BufferNo=sprintf(body,"%.5f %[3].5f %[3].5f %[3].5f %[3].5f %[3].5f %[3].5f %[3].5f\n",
a1,a2,a3,a4,a5,a6,a7,a8);
Presumably it's a char *
(alhtough I'm just guessing), which means you are trying to write a bunch of number values to a constant string capable of holding exactly zero characters. Since it's a constant, it's non-writeable.
Change it to char body[1000];
or something similar.
这篇关于错误写入在Visual Studio文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!