我有一个程序分布在 3 个不同的 C 文件中,其中包含 2 个头文件。我最初有一个标题“Player.h”,我用来保存“地图”结构(等等):
#ifndef PLAYER_H_INCLUDED
#define PLAYER_H_INCLUDED
typedef struct map{
float x;
float y;
}map;
/// some other functions and structures///
#endif
Run Code Online (Sandbox Code Playgroud)
我想将它移动到它自己的头文件“Map.h”中,以便与其他与地图相关的函数和结构一起使用。
#ifndef MAP_H_INCLUDED
#define MAP_H_INCLUDED
typedef struct map{
float x;
float y;
}map;
#endif
Run Code Online (Sandbox Code Playgroud)
我照常制作了 Map.c 文件,在其中编写了一个可以工作的函数,但我还没有在 main.c 中调用该函数。我在 main.c 中制作了“map”数据结构,如下所示:
#include "Player.h"
#include "Map.h"
int main(){
... /// some other stuff being done
map map;
map.x = 0;
map.y = 0;
... /// more stuff being done
callfunctioninplayer(&map, /// other variables///)
}
Run Code Online (Sandbox Code Playgroud)
所以我在 …