Reputation: 1881
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
Upvotes: 0
Views: 330
Reputation: 76888
sscanf(line, "%*c%*c%f%f%f", &vn[normCount].vn1, &vn[normCount].vn2, vn[normCount].vn3);
^^^^
You forgot an &
. This is causing the value contained in vn[normCount].vn3
to be evaluated as a memory address (which you obviously don't have access to write to).
Upvotes: 0
Reputation: 20764
the type of arguments supplied to scanf i wrong:
sscanf(line, "%*c%*c%f%f%f",
&vn[normCount].vn1,
&vn[normCount].vn2,
&vn[normCount].vn3); // address
Upvotes: 0
Reputation: 5456
You forgot the &
before vn[normCount].vn3
.
By the way, what is the point of line[1] == 'n' && line[1] != 't'
?
Upvotes: 4