0

I am getting errors for the below code as

(18) : error C2064: term does not evaluate to a function taking 1 arguments

(18) : error C2227: left of '->str' must point to class/struct/union/generic type

(20) : error C2064: term does not evaluate to a function taking 1 arguments

(20) : error C2227: left of '->str' must point to class/struct/union/generic type

I have declared the *p as a pointer to the struct in the main function. I could not identify where i have done the mistake.Isnt *p similar to *p+0?

#include "stdafx.h"
#include<stdio.h>

int main()
{
    struct s1{
        char *str;
        struct s1 *ptr;
    };
    static struct s1 arr[]={{"Bangalore",arr+1},{"Hyderabad",arr+2},{"Kerala",arr}};
    struct s1 *p[3];
    int i;
    for(i=0;i<=2;i++)
        p[i]=arr[i].ptr;
    printf("\n%s"(*p)->str);
    printf("\n%s",(++*p)->str);
    printf("\n%s"((*p)++)->str);
    return 0;
}
1
  • 1
    Look at your calls to printf() (which appears to be what the errors are actually referring to). "\n%s"(*p)->str is not a valid expression, nor is "\n%s"((*p)++)->str. Commented Aug 15, 2011 at 5:13

1 Answer 1

2

There are missing commas in your code:

printf("\n%s"(*p)->str);
...
printf("\n%s"((*p)++)->str);

Should have been:

printf("\n%s", (*p)->str);
...
printf("\n%s", ((*p)++)->str);

Are they just missing in the code you post here, or also on your real code?

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

3 Comments

:Yeah correctly pointed out. I missed the comma.Now i could get the output.I have a doubt in this question.Is *p[0] and *p are the same. Wont *p is like a base pointer for the array of pointers that cannot be changed with increment?
@Beata: the expressions (++*p) and ((*p)++) aren't incrementing p (which is an array), they are incrementing the pointer that happens to be in the first element of the array named p.
@Michael:Thanks michael.Is this what i thought is right that incrementing *p (i.e. (++*p) and ((*p)++)) will point to *p[1].

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.