Hello, I am very new to C++ and have this error message with my code. EXC_BAD_ACCESS (code=1, address=0x0). i am more comfortable with using codeblock at my school library but now i have to use xcode on my mac.
the issue happens at filterData[i] = (1/50) * sum; any help would be great thank you!
Move line 19 to line 38. At line 19 countlines is still zero, so you're creating an std::vector with zero elements, and then on line 49 you're accessing it out of bounds.
Also, 1/50 is exactly zero. You need to multiply sum by 1.0/50.0.
Line 52 used the function "max_element()". This is from the header file "<algorithm>" which you are missing.
Try to avoid using global variables. This may seem easy right not, but could be a bigger problem in the future.
The best I can tell the function "number" is never used.
You wrote:
1 2 3 4 5 6 7 8 9 10
if (!rawECGdata.is_open())
{
cout << "error cant open " << endl;
}
while (rawECGdata >> values)
{
countlines++;
data.push_back(values);
}
Good start, but after you print the error message you continue with the while loop not being able to read anything.
What would work better is:
1 2 3 4 5 6
if (!rawECGdata)
{
cout << "error cant open " << endl;
return 1; // <--- No point in continuing with the program.
}
This checks more than just the file being open. Then you leave the program to fix the problem. Since (0) zero means a normal return any number greater than zero denotes a problem.