Reputation: 1927
I would be most grateful if people could have a look over this snippet of code and let me know what could a possible cause for the floating point exception.
Info:
I am confused because there is no division, float or integer, that could cause this.
for (count = 0; count < sizeof(branches); count++){
if (fgets(line,sizeof(line),fp)==NULL)
break;
else {
int branch_taken = line[16] - 48;
branches[count] = branch_taken;
}
}
Upvotes: 0
Views: 766
Reputation: 213180
sizeof(branches)
is a size in bytes - you need to use a constant which represents the number of elements i.e. 200, otherwise you will be exceeding the bounds of your branches
array, which will result in Undefined Behaviour.
Your code should probably look something like this:
#define NUM_BRANCHES 200
int branches[NUM_BRANCHES];
for (count = 0; count < NUM_BRANCHES; count++)
{
...
Upvotes: 7