Codeblocks 模块化编程 头文件

Codeblocks 模块化编程

我们新建一个c工程,默认会有main.c

接下来

第一步新建 new.h   new.c

第二步新建two.h    two.c

注意在保存.h 和.c的时候把下面的两项编译选项都勾上

一般情况下我们可以在头文件中这么写声明,也可以使用cd自带的头文件声明

#ifndef _X_H_

#define _X_H_

 

#endif



下面是测试代码

MAIN.C

#include <stdio.h>
#include <stdlib.h>
#include "new.h"
#include "two.h"

int main()
{
    printf("Hello world!\n");
    show_one();
    show_two();
    return 0;
}

new.h


#ifndef NEW_H_INCLUDED
#define NEW_H_INCLUDED


extern void show_one();


#endif // NEW_H_INCLUDED



new.c


#include <stdio.h>
void show_one()
{
    printf("hello, i am one!!!\n");
}

---------------------------------------------------------------------------------------

two.h


#ifndef TWO_H_INCLUDED
#define TWO_H_INCLUDED
extern void show_two();
#endif // TWO_H_INCLUDED


two.C


#include <stdio.h>
void show_two()
{
    printf("hello, i am two!!!!\n");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值