在C中调用结构

cod*_*ude -1 c struct

我有以下代码:

typedef struct {
   double x, y;
} point_t ;


typedef struct {
    point_t a, b, c;
} triangle_t;

int read_point(point_t * const point) {
    int status = scanf(" (&lf,&lf)", &point_t.x, &point_t.y);
    return(status);
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试读取用户为三角形的顶点输入的x和y坐标(点a,b和c.)但是,我得到一个奇怪的错误,在scanf函数中强调了"point_t"的两个实例.

不允许输入名称.

这是怎么回事?

Tus*_*har 8

将其更改为:

int status = scanf(" (%lf,%lf)", &(point->x), &(point->y));
Run Code Online (Sandbox Code Playgroud)

请记住使用变量名称point,而不是类型名称point_t.还需要注意的是,必须->在指针类型上使用运算符(它相当于取消引用它,然后使用成员运算符[ p->x == (*p).x]).