注册 登录
编程论坛 C语言论坛

大神帮忙看看哪出问题了,结构指针.谢谢

白白白小白 发布于 2021-11-24 17:27, 1422 次点击
大神帮忙看下这个代码哪里有问题,出现error
程序代码:
#include<stdio.h>
struct point{
    int x;
    int y;
};

struct point* getStrcut(struct point*);
void output(struct point);
void print(const struct point *p);

int main(int argc,char const *argv[])
{
    struct point y={0,0};
    getStruct(&y);
    output(y);
    output(*getStruct(&y));
    print(getStruct(&y));
    getStruct(&y)->x = 0;
    *getStruct(&y) = (struct point){1,2};
}

struct point* getStruct(struct point *p)
{
    scanf("%d",&p->x);
    scanf("%d",&p->y);
    printf("%d,%d",p->x,p->y);
    return p;
}

void output(struct point p)
{
    printf("%d,%d",p.x,p.y);
}

void print(const struct point *p)
{
    printf("%d,%d",p->x,p->y);
}


只有本站会员才能查看附件,请 登录
2 回复
#2
lin51616782021-11-24 17:37
struct point* getStrcut(struct point*);
getStruct(&y);
拼写错误
#3
白白白小白2021-11-24 18:42
回复 2楼 lin5161678

谢谢!找半天没找到...
1