Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

c - passing array of structure as a function parameter

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("
trans_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("
fund_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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 &


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...