C 访问不同源文件中的结构
我想从file1.c中使用的结构访问数据,并访问file2.c中的数据 我已经宣布C 访问不同源文件中的结构,c,structure,C,Structure,我想从file1.c中使用的结构访问数据,并访问file2.c中的数据 我已经宣布 in file1.c struct value { unsigned char time[6]; unsigned char date[6]; unsigned char number[6]; } entry; 其中,结构由值填充,然后希望使用file2.c中的结构 我应该如何使用结构范围,以便也可以在file2.c中访问它。您可以使用
in file1.c
struct value
{
unsigned char time[6];
unsigned char date[6];
unsigned char number[6];
} entry;
其中,结构由值填充,然后希望使用file2.c中的结构
我应该如何使用结构范围,以便也可以在file2.c中访问它。您可以使用
extern
关键字,并在新文件中声明struct
变量
extern struct value entry;
您知道声明和定义之间的区别吗?非常感谢@Sakthi Kumar。这样我就可以访问file1.c中填充的值了。
extern struct value entry;