开发者

Array of pointers pointing to a struct variable

开发者 https://www.devze.com 2023-03-28 16:00 出处:网络
I am getting errors for the below code as (18) : error C2064: term does not evaluate to a function taking 1 arguments

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",a开发者_如何学编程rr}};
    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;
}


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消