Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C语言中的调用结构_C_Struct - Fatal编程技术网

C语言中的调用结构

C语言中的调用结构,c,struct,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); } 我

我有以下代码:

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);
}
我试图读取用户为三角形顶点(点a、点b和点c)输入的x和y坐标。然而,在scanf函数中,我在“点t”的两个实例下都出现了一个奇怪的错误

不允许使用类型名称

发生了什么事?

将其更改为:

int status = scanf(" (%lf,%lf)", &(point->x), &(point->y));
记住使用变量名
,而不是类型名
。还需要注意的是,必须在指针类型上使用运算符
->
(这相当于取消对它的引用,然后使用成员运算符[
p->x==(*p).x

尝试此代码)

typedef struct {
   double x;
   double y;
} point_t ;


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

int read_point(point_t * point) {
    int status = scanf(" (&lf,&lf)", point->x, point->y);
    return(status);
}
我认为在struct中,您应该用它的类型声明每个字段;多重声明为
int x,y
不起作用。
其次,您正在传递一个指针,因此要访问,您应该使用参数的名称(“点”是这种情况),这样
point->field
(*point).field
而不是
&point

我强烈建议将
&lf
更改为
%lf
;)@丹尼尔菲舍尔的观点很好:)我甚至没有看那个部分。这解决了我的问题!我想我看错了。谢谢你的帮助!