一个例子
- 首先创建一个工作文件夹,在其中创建头文件
funtions.h
,并写入一下代码:
#include<stdio.h>
void printstr(char *s);
void printstr(char *s)
{
puts(s);
}
- 然后创建测试文件
test.c
,并写入一下代码:
#include <stdlib.h>
#include "functions.h"
//以"filename.h" 格式引用头文件,则编译器从当前用户的工作目录开始搜索
int main()
{
char a[] = "hello world";
printstr(a);
system("pause");
return 0;
}
总结
在引用头文件时使用这种格式:include "filename.h"
, 以双引号包裹文件名,则编译器从当前用户的工作目录开始搜索,若当前工作目录不存在此文件,则会去便准库中查找该文件,若用双箭头格式,则编译器只会在标准库目录中搜索。
如有错漏恳请指正!