我组织了我的程序,将每个实体分割到它自己的文件中。 这是这样的。如何在文件中正确拆分C程序并包含它?
main.c
#include "student.h"
#include "subject.h"
#include "classroom.h"
#define PI 3.14
int sum(int a, int b);
student.h
typedef struct st student;
student.c
#include "student.h"
subject.h
typedef struct sb subject;
subject.c
#include "subject.h"
classroom.h
typedef struct cr classroom;
classroom.c
#include "classroom.h"
我的问题是,里面教室我需要学生和主题。 我应该如何包含这个?我应该在classroom.h还是classroom.c?
#include "student.h"
#include "subject.h"
其次,我对的main.c东西,被所有的然后像总和()和PI
它是如何包括头实现的正确途径或者在实现文件中包含头文件?并且我应该包含头文件还是实现文件?
如果我把所有东西扔在一个文件上,它编译得很好,但我没有这样做,它不能编译。
参数“头文件应该包括他们自己需要的所有东西”是非常有用的,所以使用的东西,但不需要任何声明,例如'strcpy()',我应该只包含'string.h'在'xc'文件中,而不是'xh'中,对吗? –
是的,如果你使用'strcpy()'在“x.h”中没有'inline'函数,那么就不需要“x.h”来包含“string.h”。 –