将结构体数组作为函数参数传递

发布于 2024-11-03 20:47:11 字数 1036 浏览 0 评论 0原文

typedef struct What_if
{
    char   price                 [2];
} what_if ;

what_if  what_if_var[100];

int format_input_records();

int process_input_records(what_if *what_if_var);

int format_input_records()
{
    if (infile != NULL )
    {
        char mem_buf [500];

        while ( fgets ( mem_buf, sizeof mem_buf, infile ) != NULL ) 
        {
            item = strtok(mem_buf,delims);     
            strcpy(what_if_var[line_count].trans_Indicator,item) ;
            printf("\ntrans_Indicator     ==== : : %s",what_if_var[line_count].price);
            process_input_records(&what_if_var);
            line_count=line_count+1;
        }
    }
}

int process_input_records(what_if *what_if_var)
{
    printf("\nfund_price process_input_records    ==== : : %s",what_if_var[line_count]->price);
    return 0;
}

我在这里遇到错误,任何人都可以告诉我我在这里犯了什么错误吗?

不允许在类型“struct {...}*”和“struct {...}(*)[100]”之间进行函数参数赋值。

需要指向结构或联合的指针。

typedef struct What_if
{
    char   price                 [2];
} what_if ;

what_if  what_if_var[100];

int format_input_records();

int process_input_records(what_if *what_if_var);

int format_input_records()
{
    if (infile != NULL )
    {
        char mem_buf [500];

        while ( fgets ( mem_buf, sizeof mem_buf, infile ) != NULL ) 
        {
            item = strtok(mem_buf,delims);     
            strcpy(what_if_var[line_count].trans_Indicator,item) ;
            printf("\ntrans_Indicator     ==== : : %s",what_if_var[line_count].price);
            process_input_records(&what_if_var);
            line_count=line_count+1;
        }
    }
}

int process_input_records(what_if *what_if_var)
{
    printf("\nfund_price process_input_records    ==== : : %s",what_if_var[line_count]->price);
    return 0;
}

I am facing error here, can any one please tell me what is the mistake i done here?

Function argument assignment between types "struct {...}*" and "struct {...}(*)[100]" is not allowed.

Expecting pointer to struct or union.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢望 2024-11-10 20:47:11

数组本质上已经是指向已分配数组长度的某个内存空间的指针。因此你应该简单地这样做:

process_input_records(what_if_var);

没有 &

An array is intrinsically already a pointer to some space of memory where the length of the array has been allocated. Therefore you should simply do:

process_input_records(what_if_var);

without &

生来就爱笑 2024-11-10 20:47:11

错误就在这里:

process_input_records(&what_if_var);
                      ^

您正在获取数组的地址,这相当于 what_if**,而该函数只获取 what_if*

process_input_records(what_if_var);

请注意,您可能希望将数组的大小作为第二个参数传递给 process_input_records,以便该函数知道数组中有多少个元素:

process_input_records( what_if_var, sizeof  what_if_var / sizeof *what_if_var );

The error lies here:

process_input_records(&what_if_var);
                      ^

You're taking the address of an array, which is equivalent to what_if**, while the function takes only what_if*.

process_input_records(what_if_var);

Note that you probably want to pass the size of the array as a second parameter to process_input_records, so the function knows how many elements are in the array:

process_input_records( what_if_var, sizeof  what_if_var / sizeof *what_if_var );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文