首先新建一个“.h”头文件,并输入以下程序:
#include<stdio.h> //另一个.c文件所需函数函数所在的头文件
#ifndef printq_h
#define printq_h
void printHellot(); //.c程序中函数的申明
#endif
注意:自定义的库的引用要用“双引号”而非“<>”
实例:
1、main.c
#include<stdio.h>
#include"printq.h"
int main()
{
printHello();
return 0;
}
2、printq.h
#include<stdio.h>
#ifndef printq_h
#define printq_h
void printHellot();
#endif
3、printq.c
#include "printq.h"
void printHello()
{
printf("hello word!\n");
}

本文介绍了如何在C语言中通过创建头文件和.c源文件来实现函数调用。在main.c中,通过包含printq.h头文件,调用printq.c中的printHello()函数,输出'hello world!'。这种方式展示了C语言中自定义库的使用和函数声明的实践方法。
最低0.47元/天 解锁文章
2517

被折叠的 条评论
为什么被折叠?



