我正在尝试访问位于头文件' Header.h'中的结构中的变量New_Id
。这是从一个名为Main.c的
Header.h
#ifndef HEADER.H
#define HEADER.H
#include <stdio.h>
#include <stdint.h>
typedef struct {
uint32 New_Id;
} IdType;
我正在尝试访问此变量并从我的C文件中为其分配一个值&#39; Main.c&#39;以下列方式
#include <Header.h>
#include <stdint.h>
#include <stdio.h>
void Main (void) {
//code independent of the structure.-----
-----------------------------------//
//Now accessing the structure variable//
IdType.New_id =2;
}
但出于某种原因,我不明白它一直在说“Field New_Id无法解决”。它没有说结构本身。有人可以告诉我这里我做错了什么。
答案 0 :(得分:4)
IdType
是一种数据类型。要访问变量,您需要创建IdType
类型的对象,如下所示:
IdType id;
id.New_id=2;
答案 1 :(得分:3)
在您的代码中,IdType
本身不是变量,而是数据类型。您需要使用该类型的变量来访问该结构变量的成员。