gpt4 book ai didi

c - 将结构的指针成员传递给函数时出现错误 )

转载 作者:太空宇宙 更新时间:2023-11-04 06:48:51 25 4
gpt4 key购买 nike

我是 C 的初学者。在我的程序中,我有一个结构和一个函数。我正在尝试传递结构中存在的指针作为函数中的参数。但它在点运算符处显示错误“Expected )”。这令人困惑,因为我的函数的其他参数也来自结构,但在这些结构中没有看到此错误。

我尝试将函数的返回类型更改为所有类型,但仍然没有。

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
}

我不确定我哪里出错了,或者语法是否有误。我希望该函数接受参数,但事实并非如此。

最佳答案

在另一个函数中包含函数是 not possible in C ...

因此,您的代码应该看起来像这样:

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);
}

关于c - 将结构的指针成员传递给函数时出现错误 ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54319696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com