首页 > 解决方案 > 在 C 中初始化特定成员

问题描述

我想定义结构

    #include <stdio.h>
#include <stdint.h>
#include <time.h>
//#include "templog.h"
#define DATE_SIZE      5
 typedef struct {
    int id;
    int year;
    int month;
    int mday;
    float min_temp, max_temp;
    } tempValue_t

数据是

tempValue_t temps[DATE_SIZE] =
    { 0, { .tm_year = 2015, .tm_mon = 0, .tm_mday = 1 }, 19.26, 20.76 },

我收到了消息

error field name not in record or union initializer

标签: pointersstruct

解决方案


最后发现结构成员可以初始化,嵌套结构也可以用(.)初始化。


推荐阅读