typedef struct{ uint8_t ID; uint32_t Parame; uint8_t Battery; uint8_t Voltage; }config_t;用另外一个结构体给他赋值
时间: 2024-04-21 20:20:32 浏览: 204
typedef struct{
uint8_t ID;
uint32_t Parame;
uint8_t Battery;
uint8_t Voltage;
} config_t;
另外一个结构体给config_t赋值的方法如下[^1]:
```c
typedef struct{
uint8_t ID;
uint32_t Parame;
uint8_t Battery;
uint8_t Voltage;
} config_t;
typedef struct{
uint8_t ID;
uint32_t Parame;
uint8_t Battery;
uint8_t Voltage;
} another_config_t;
int main(){
another_config_t another_config;
another_config.ID = 1;
another_config.Parame = 100;
another_config.Battery = 80;
another_config.Voltage = 5;
config_t config;
config.ID = another_config.ID;
config.Parame = another_config.Parame;
config.Battery = another_config.Battery;
config.Voltage = another_config.Voltage;
return 0;
}
```
在上述代码中,我们定义了两个结构体config_t和another_config_t,然后我们创建了一个another_config_t类型的变量another_config,并给其成员赋值。接着,我们创建了一个config_t类型的变量config,并将another_config的成员值赋给config的对应成员。这样就完成了用另外一个结构体给config_t赋值的操作。
阅读全文