I have a function which searches for extrema in some data array. It takes pointer to data, some parameters and a pointer to struct array where the result is stored. The function returns the length of the resulting struct array.
int FindPeaks(float *data, int WindowWidth, float threshold, struct result *p)
{
int RightBorder = 0;
int LeftBorder = 0;
bool flag = 1;
int i = 0;
int k = 0;
while(1)
{
flag = 1;
if (WindowWidth >= 200) cout << "Your window is larger than the signal! << endl";
if (i >= 200) break;
if ((i + WindowWidth) < 200) RightBorder = i + WindowWidth;
if ((i - WindowWidth) >= 0) LeftBorder = i - WindowWidth;
for(int j = LeftBorder; j <= RightBorder; j ++)
{
if (*(data + i) < *(data + j))
{
flag = 0;
break;
}
}
if (flag && *(data + i) >= threshold && i != 0 && i != 199)
{
struct result pointer = p + k;
pointer.amplitude = *(data + i);
pointer.position = i;
i = i + WindowWidth;
k++;
}
else
{
i ++;
}
}
return k;
}
I'm confused with a reference to i-th struct field to put the result in there. Am I doing something wrong?
struct result pointer = p + k;:, is have a feeling it should be:struct result* pointer = p + k;structprefix. What resource are you using to learn C++?