终于跑起来了,含自定义 include .h 的c语言程序,超开心呀!

header files contain prototypes for functions you define in a .c or .cpp/.cxx file (depending if you're using c or c++).

You want to place #ifndef/#defines around your .h code so that if you include the same .h twice in different parts of your programs, the prototypes are only included once

这本c语言的书不错,学习之,加油!!! http://publications.gbdirect.co.uk/c_book/chapter1/functions.html

参考:http://stackoverflow.com/questions/7109964/creating-your-own-header-file-in-c

foo.h

#ifndef FOO_H_   /* Include guard */
#define FOO_H_ int foo(int x); /* An example function declaration */ #endif // FOO_H_

foo.c

#include "foo.h"  /* Include the header (not strictly necessary here) */

int foo(int x)    /* Function definition */
{
return x + 5;
}

main.c

#include <stdio.h>
#include "foo.h" /* Include the header here, to obtain the function declaration */ int main(void)
{
int y = foo(3); /* Use the function here */
printf("%d\n", y);
return 0;
}

To compile using GCC

gcc -o my_app main.c foo.c

Creating your own header file in C的更多相关文章

  1. 【iOS】The differences between Class Extension and Header File 类扩展与头文件的区别

    . As the name suggests, they extend the class. A class continuation is another name. The class exten ...

  2. auto make System.map to C header file

    #!/bin/bash # auto make System.map to C header file # 说明: # 该脚本主要是将Linux内核生成的System.map文件中的符号.地址存入结构 ...

  3. c++预编译问题:fatal error C1083: Cannot open precompiled header file: 'Debug/DllTest.pch': No such file or d

    1)单独编译StdAfx.cpp 2)编译所有(即按Ctrl+F7) 这时因为该模块没有包括预编译头文件“stdafx.h”的缘故.VC用一个stdafx.cpp包含头文件stdafx.h,然后在st ...

  4. 进度记录 和 安装imagick时Cannot locate header file MagickWand.h错误的解决

    修改php.ini文件,已使php支持扩展的功能 [root@localhost imagick-2.2.2]# ./configure --with-php-config=/usr/local/ph ...

  5. fatal error C1083: Cannot open precompiled header file: 'Debug/xxoo.pch': No such file or directory

    fatal error C1083: Cannot open precompiled header file: 'Debug/xxoo.pch': No such file or directory ...

  6. About Why Inline Member Function Should Defined in The Header File

    About why inline member function should defined in the header file. It is legal to specify inline on ...

  7. Header File Dependencies

    [Header File Dependencies] 什么时候可以用前置声明替代include? 1.当 declare/define pointer&reference 时. 2.当 dec ...

  8. fatal error C1853: '<filename>' is not a precompiled header file

    当编译c和c++混合的项目时,会出现如下类似的错误 fatal error C1853: '<filename>' is not a precompiled header file 解决方 ...

  9. 原文:I don’t want to see another “using namespace xxx;” in a header file ever again

    http://stackoverflow.com/questions/5849457/using-namespace-in-c-headers http://stackoverflow.com/que ...

随机推荐

  1. Redis高可用配置(Keepalived)

    主:172.16.0.104 备:172.16.0.105 VIP:172.16.0.107 客户端直接连VIP,当master 104的redis挂掉后,105作为master.当104重启后,10 ...

  2. 草料生成app自动下载的二维码

    草料官网http://cli.im/app 填写iOS和安卓的appid就好了

  3. Apple 移动设备绑定动态生成元素点击事件$(document).on('click',element,callback)失效解决方法

    今天在工作中刚接触到了微信社区相关的开发工作,测试的时候发现,动态生成元素的点击事件在andriod设备上可以触发,而在apple移动设备上却无法触发.好奇的我赶紧百度了下,很快就在stackover ...

  4. Xcode-App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.

    在xcode中上报数据时候,logserver一直没有数据,后来发现控制台有一个提示: 找了半天是因为Xcode7禁止明码的HTTP请求,而自己使用的是Xcode7.2.1 解决办法:修改info.p ...

  5. linux 查看日志

    第一步 :提交自己目录文件(先到自己目录下载最新文件-->合并-->提交到临时目录temp-->在提交到master总目录-->其他关联master远 程分支的目录.就可以pu ...

  6. TortoiseGit - Win7使用Gitblit搭建Git服务器教程

    第一步:下载Java并且安装 第二步:配置Java环境变量环境变量 --> 系统变量1新建:变量名:JAVA_HOME变量值:D:\Program Files (x86)\Java\jdk1.6 ...

  7. updateMany

    db.tblDaily.updateMany( {"Comments.ViewCount":0}, {$addToSet:{"Comments.$.CommentDate ...

  8. Newtonsoft.Json使用

    SkuBean sb = (SkuBean)Newtonsoft.Json.JsonConvert.DeserializeObject(jobj.ToString(), typeof(SkuBean) ...

  9. Python从json中提取数据

    #json string:s = json.loads('{"name":"test", "type":{"name": ...

  10. 1.建立exception包,编写TestException.java程序,主方法中有以下代码,确定其中可能出现的异常,进行捕获处理。

    package d0923; public class TestException { public static void main(String[] args) { for(int i=0;i&l ...