访问C中不同文件的结构

Var*_*n U 2 c struct

我有以下C代码

文件名:abc.c

#include<stdio.h>

struct abc{
int xxx;
float yyy;
};
Run Code Online (Sandbox Code Playgroud)

我需要在另一个名为def.c的文件中访问上面的结构

任何人都可以解释我如何实现这一目标吗?

谢谢!

Kis*_*ore 7

// mystructs.h
struct abc{
    int xxx;
    float yyy;
};


//abc.c
#include "mystructs.h"
struct abc var1;


//another_file.c
#include "mystructs.h"
struct abc var2;
Run Code Online (Sandbox Code Playgroud)

  • 即使只是为了打破代码块,一些单词也会很好. (2认同)
  • 这是关于如何编写更高质量的答案的建议。 (2认同)