简体   繁体   中英

Error expected ) while passing a pointer member of a structure to a function

I am a beginner to C. In my program i have a structure and a function. I'm trying to pass a pointer which is present in the structure as an argument in my function. But it is showing the error "Expected )" at the dot operator. This is confusing because the other arguments of my function are from the structure as well but this error is not seen in those.

I tried changing the return type of the function to all types and still nothing.

struct signal
{
bool *input;
int previousop;
int n;
}s; //my structure
void noiseremove(bool *input, int n, int count1, int count0, bool 
previousop)//function i declared and defined before main function
{//my function here}
void main()
{
void noiseremove(bool *s.input , int s.n, int s.count1, int s.count0, bool 
s.previousop); //this is where i call the function and facing an error at 
*s.input 
}

I'm not sure where i'm going wrong here or if the syntax is wrong. I expect the function to accept the parameters but it isn't.

Having functions inside another function is not possible in C ...

So, your code should somewhat look like this:

struct signal
{
    bool *input, previousop;
    int n, count0, count1;
} s;

void noiseremove(bool *input, int n, int count1, int count0, bool previousop)
{
    /* Try using multi-line comments since single-line comments can comment out the end
       braces as well...*/
}

void main()
{
    /* Initialize the structure before accessing any of its variables, or it will lead
       to undefined behavior! */
    s = {0};
    /* Don't declare the identifiers again... It is 'syntax error' and 
       your calling convention doesn't in the least look like a calling 
       convention but more like a function declaration with invalid identifiers
       for the parameters... */
    noiseremove(s.input , s.n, s.count1, s.count0, s.previousop);
}
struct signal
{
    bool *input, previousop;
    int n, count1, count0;
} s; //my structure

void noiseremove(bool *input, int n, int count1, int count0, bool previousop) //function i declared and defined before main function
{
    // my function here
}
void main()
{
    // this should compile but s has not been initialized
    noiseremove(s.input , s.n, s.count1, s.count0, s.previousop);
    // not sure what you were going for here
    //*s.input 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM