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_Pointers_Struct_Assign - Fatal编程技术网

C 从指针指定结构的成员值

C 从指针指定结构的成员值,c,pointers,struct,assign,C,Pointers,Struct,Assign,我有一个结构和一个函数,返回指向它读取的结构的指针: typedef struct cal_t { float xm; float ym; float xn; float yn; } cal_t; struct cal_t *lld_tpReadCalibration(void); 在其他地方,我确实有该结构的一个实例: struct cal_t cal; 现在我需要将该结构实例的值赋给我得到指针返回的结构的值。所以我想要的是cal.xm与lld_

我有一个结构和一个函数,返回指向它读取的结构的指针:

typedef struct cal_t {
    float xm; 
    float ym; 
    float xn; 
    float yn; 
} cal_t;


struct cal_t *lld_tpReadCalibration(void);
在其他地方,我确实有该结构的一个实例:

struct cal_t cal;
现在我需要将该结构实例的值赋给我得到指针返回的结构的值。所以我想要的是cal.xm与lld_tpReadCalibration()中的cal->xm的值相同。象征性地:

struct cal_t cal;

cal = lld_tpReadCalibration();
但这当然行不通:

error: incompatible types when assigning to type 'volatile struct cal_t' from type 'struct cal_t *'
我怎样才能使它按我想要的方式工作


谢谢您的帮助。

您需要以某种方式取消对指针的引用。您正在从函数返回指针,因此您正在查找
*
运算符或
->
,这当然是
*
的同义词

cal
定义为
struct-cal\u t
,函数返回指向
cal\u t
的指针。因此,您需要取消对指针的引用

cal = *lld_tpReadCalibration();

您需要以某种方式取消对指针的引用。您正在从函数返回指针,因此您正在查找
*
运算符或
->
,这当然是
*
的同义词

cal
定义为
struct-cal\u t
,函数返回指向
cal\u t
的指针。因此,您需要取消对指针的引用

cal = *lld_tpReadCalibration();

函数返回值是struct cal_t*,它是指针类型

因此,您应该将返回值指定给类型为struct cal_t*的变量

比如说,

struct cal_t *cal_ptr;

cal_ptr = lld_tpReadCalibration();

函数返回值是struct cal_t*,它是指针类型

因此,您应该将返回值指定给类型为struct cal_t*的变量

比如说,

struct cal_t *cal_ptr;

cal_ptr = lld_tpReadCalibration();