[英]C++ Error STATUS_ACCESS_VIOLATION
I'm getting that error by running this simplest code: 我通过运行这个最简单的代码得到了这个错误:
#include "stdio.h"
#include "stdlib.h"
int main()
{
FILE* in;
FILE* out;
in = fopen("foo.in", "r");
out = fopen("bar.out", "w+");
int something;
fscanf(in, "%i", something);
fprintf(out, "%i", something);
fclose(in);
fclose(out);
return 0;
}
I'm running it out of Sublime Text 3. 我是用Sublime Text 3运行的。
fscanf
expects a pointer, meaning that it modify the value of something
while in the function fscanf
if you send it by copy the value will be correct while in scope (ie while in fscanf
) but the result is never returned so your copy of something
is never changes, (ie it's still not initialized). fscanf
预期的指针,这意味着修改的价值something
,而在功能fscanf
如果通过复制值发送这将是正确的,而在范围(即同时fscanf
),但结果再也没有回来让你的副本something
是永远不会改变,(即它仍未初始化)。
so what you need to do: 那么你需要做什么:
int something;
fscanf(in, "%i", &something);
fprintf(out, "%i", something);
and it should work, if you are trying to read an integer from foo.in
and write it to bar.out
. 它应该工作,如果你试图从
foo.in
读取一个整数并将其写入bar.out
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.