文件解析期间访问冲突写入位置
我已经将问题缩小到几行代码,但我无法识别导致“访问冲突写入位置”的函数调用的非法内容,我希望更好的 C 语言可以帮助我?
代码中断的输入是
vn 0.185492 -0.005249 0.982604
我想将 3 个浮点值分配给 Struct vn 数组
struct Normals{
float vn1;
float vn2;
float vn3;
};
struct Normals vn[50000];
,而崩溃的代码是
if (line[0] == 'v' && line[1] == 'n' && line[1] != 't'){
sscanf(line, "%*c%*c%f%f%f",
&vn[normCount].vn1,
&vn[normCount].vn2,
vn[normCount].vn3);
normCount++;
}
任何提示都很棒!谢谢
Ive narrowed the issue down to a few lines of code but im having trouble identifying what is illegal about the function call causing a "Access violation writing location" I was hoping someone better with C could help me out?
The input the code is breaking on is
vn 0.185492 -0.005249 0.982604
I want to assign the 3 float values to an Array of Struct vn
struct Normals{
float vn1;
float vn2;
float vn3;
};
struct Normals vn[50000];
and the code that is crashing is
if (line[0] == 'v' && line[1] == 'n' && line[1] != 't'){
sscanf(line, "%*c%*c%f%f%f",
&vn[normCount].vn1,
&vn[normCount].vn2,
vn[normCount].vn3);
normCount++;
}
Any tips would be great! Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您忘记了
vn[normCount].vn3
之前的&
。顺便说一句,
line[1] == 'n' && 的意义是什么?行[1] != 't'
?You forgot the
&
beforevn[normCount].vn3
.By the way, what is the point of
line[1] == 'n' && line[1] != 't'
?提供给 scanf 的参数类型我错误:
the type of arguments supplied to scanf i wrong:
您忘记了
&
。这导致vn[normCount].vn3
中包含的值被评估为内存地址(您显然无权写入)。You forgot an
&
. This is causing the value contained invn[normCount].vn3
to be evaluated as a memory address (which you obviously don't have access to write to).