永发信息网

c语言头文件怎么写~!!最好举个例子!!非常感谢!!

答案:4  悬赏:50  手机版
解决时间 2021-12-01 19:56
  • 提问者网友:末路
  • 2021-12-01 09:36
c语言头文件怎么写~!!最好举个例子!!非常感谢!!
最佳答案
  • 五星知识达人网友:荒野風
  • 2021-12-01 11:07

#ifndef MYHEADFILE
#define MYHEADFILE
void InitInterpolation();
void Draw_Border();
void Draw_Background();
void Draw_Gray();
#endif

#include "test.h"

头文件一般用于多个源码的工程,当然,单源码可以写头文件,这个只是一种风格或习惯,一般是程序的声明部分写在.h中,如你的
char mainmenu(void);
char getBookType (void);
char bookItem (void);
int getBookNumber(void);
还有就是fiction,nonFiction的声明,可写成
extern int fiction;
extern int nonfiction;
全部回答
  • 1楼网友:怙棘
  • 2021-12-01 13:58
头文件随便写什么都可以
比如
h.h
#include

然后你就不用在主函数里写include
了,直接写#include
  • 2楼网友:長槍戰八方
  • 2021-12-01 13:08
头文件创建全部项目,总共包含三个文件:

//【01】function_01.h 代码如下:

#include 
void print_hello(int a, int b, int c);
void print_world(int a, int b);//【02】function_01.cpp 代码如下:
#include "function_01.h"
void print_hello(int a, int b, int c)
{
printf("hello ");
}

void print_world(int a, int b)
{
printf("world ");
}//【03】main.cpp 代码如下:
#include "function_01.h"
int main()
{
print_hello(1, 1, 1);
print_world(1, 1);

getchar();
return 0;
}


//程序运行结果为:
hello
world
  • 3楼网友:舊物识亽
  • 2021-12-01 12:04
简单办法,先写完整程序,再把一部分抽出去,抽出去的存到 自己的头文件里,在抽出的地方写 #include ...

例如,完整程序(计算平均值):
#include

double mean(double *y, int N){
int i;
double s=0.0;
for (i=0;is = s / (double) N;
return s;
}
void main()
{
double x[10]={1,2,3,4,5,6,7,8,9,10};
printf("mean = %lf\n", mean(x,10));
}
----------------------------------------------
抽出部分 存入 a_x.h :
double mean(double *y, int N){
int i;
double s=0.0;
for (i=0;is = s / (double) N;
return s;
}
--------------------------------
程序变:
#include
#include "a_x.h"
void main()
{
double x[10]={1,2,3,4,5,6,7,8,9,10};
printf("mean = %lf\n", mean(x,10));
}
=============================================
你要是愿意随便抽一块也可以,例如抽出(也叫 a_x.h):
double mean(double *y, int N){
int i;
double s=0.0;
for (i=0;is = s / (double) N;
return s;
}
void main()
{
------------------------
程序变:
#include
#include "a_x.h"
double x[10]={1,2,3,4,5,6,7,8,9,10};
printf("mean = %lf\n", mean(x,10));
}
==============================
语法上,功能上,两种抽法都可以。但第一种方法较好--程序可读性好,不易出错。

一般情况下,头文件里放 函数原型,全局量声明 和 函数定义。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯