zero crossing

I have this code but is not working , it keep giving me the following errors :
[Error] cannot convert 'float' to 'float*' for argument '1' to 'void zeroCrossing(float*, float*, int)'

[Error] cannot convert 'float*' to 'float' for argument '1' to 'bool getSign(float)'


[Error] cannot convert 'float*' to 'float' for argument '1' to 'bool getSign(float)'


[Error] invalid conversion from 'int' to 'float*' [-fpermissive]

enter code here

#include <iostream>
#include <cstring>
using namespace std;

void zeroCrossing(float *data, float *zerCross, int nx);
bool getSign(float data);
float array[9] = {1,2,3,0,-1,-2,-3,0,1};
float *p = array;
float f1[9];
float *p2 = f1;
int bx= 2 ;
int main() {


zeroCrossing(*p,*p2,bx);



return 0 ;

}

/* zero crossing function */
/* data = input array */
/* zerCross = output zero crossing array */
void zeroCrossing(float *data[], float *zerCross[], int nx)
{
int i;
bool sign1, sign2;

memset(zerCross, 0, nx*sizeof(float));//copies the 0 to the first characters of the string
//pointed to, by argument

for(i=0; i<nx-1; i++) /* loop over data */
{
sign1 = getSign(data[i]);
sign2 = getSign(data[i+1]);
if(sign1!=sign2) /* set zero crossing location */
zerCross[i+1] = 1;
}
}
/* get sign of number */
bool getSign(float data)
{
if(data>0) /* positif data */
return (1);
else /* negatif data */
return (0);
}
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) Your getSign function takes a single float as an argument. You've defined data as array of float*, which means that data[i] is a float*.

So, you're trying to pass a float*, where your function expects a float.

3) Similarly, zerCross is an array of float*. This means zerCross[i+1] is a float*. You're trying to set a pointer, to have a value of 1, which is an int.
Last edited on
[Error] cannot convert 'float' to 'float*' for argument '1' to 'void zeroCrossing(float*, float*, int)'
This usually means you're passing a variable, where the address a variable is expected.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void zeroCrossing(float *data, float *zerCross, int nx);

int main()
{
    float array[9] = {1,2,3,0,-1,-2,-3,0,1};
    float *p = array;

    float f1[9];
    float *p2 = f1;

    int bx= 2 ;
    zeroCrossing(*p,*p2,bx);  // kbw: *p is a float, it expects a float*, same with *p2
    zeroCrossing(array, f1, bx); // kbw: this is probably what you should be doing
}
Last edited on
Topic archived. No new replies allowed.