1
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.

4
  • Also, please work over the code indentation. It's hard to see which closing bracket matches an opening one. Commented Apr 27, 2011 at 7:58
  • Function argument assignment between types "struct {...}*" and "struct {...}(*)[100]" is not allowed. Commented Apr 27, 2011 at 7:59
  • You code sample is incomplete and wouldn't compile anyway (trans_Indicator for example isn't in your supplied What_if structure). Where does line_count come from etc... Commented Apr 27, 2011 at 8:09
  • I believe at least one of your problems is: "what_if_var[line_count]->price" needs to be "what_if_var[line_count].price" since 'what_if *what_if_var' is pointing to an array of objects, the "what_if_var[line_count]" refers to an actual object, not a pointer to an object, so you don't need to use the "->" operator Commented Apr 27, 2011 at 8:11

2 Answers 2

3

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 &

Sign up to request clarification or add additional context in comments.

7 Comments

-1 for suggesting that malloc is anywhere near similar to var[100] (iow: I liked your answer better when it didn't yet include the last sentence :)
@mmutz In my answer I am saying that the declaration of variables are sort of equivalent. I don't say that malloc is equivalent to the array declaration. My point with the malloc is just for giving a hint with the answer. I tried to be careful when I wrote it to not infer that malloc was equivalent - only that the declarations are sort of equivalent.
@msalvadores: but they're not even "sort of" equivalent. I remember when I first tried to grok the difference between stack and heap storage. Telling me back then that they were "sort of" equivalent would have thrown me off the track pretty badly. Not saying jcrshankar is such a newbie, but I'm sure some C/C++ beginners will stumble across this question and get the wrong idea :(
@mmutz In benefit of not confusing people, I agree with you, is better to remove it. I have just edited the answer to do so. Thanks for your constructive feedback.
@msalvadores: thanks, I changed my downvote into an upvote now
|
2

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

3 Comments

printf("\nfund_price process_input_records ==== : : %s",what_if_var[line_count]->price); return 0; } is this is way to print the value? because it showing error like.. Expecting pointer to struct or union
@jcrshankar: It needs to use .price, rather than ->price (see my comment on your question...)
@jcrshankar: what_if_var[line_count] is of type what_if, not what_if*, so you use . as the member selection operator, not ->, which is for pointers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.