终于跑起来了,含自定义 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. PAT 团体程序设计天梯赛-练习集 L1-016. 查验身份证

    一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, ...

  2. PAT 团体程序设计天梯赛-练习集 L1-007. 念数字

    输入一个整数,输出每个数字对应的拼音.当整数为负数时,先输出“fu”字.十个数字对应的拼音如下: 0: ling 1: yi 2: er 3: san 4: si 5: wu 6: liu 7: qi ...

  3. lorem ipsum text占位符

    Web开发者通常用lorem ipsum text来做占位符,占位符就是占着位置的一些文字,没有实际意义. 为什么叫lorem ipsum text呢? 是因为lorem ipsum是古罗马西塞罗谚语 ...

  4. 【Python@Thread】queue模块-生产者消费者问题

    python通过queue模块来提供线程间的通信机制,从而可以让线程分项数据. 个人感觉queue就是管程的概念 一个生产者消费者问题 from random import randint from ...

  5. 查看mms UA/profile

    查看彩信的UA/profile信息,当然可以通过打印log来看. 但还有一个比较简便的方法: 直接抓取一个MMS包,用网络包分析工具打开,找到承载该MMS信息的HTTP协议包即可查看:

  6. 【Machine Learning in Action --4】朴素贝叶斯过滤网站的恶意留言

    背景:以在线社区的留言板为例,为了不影响社区的发展,我们需要屏蔽侮辱性的言论,所以要构建一个快速过滤器,如果某条留言使用了负面或者侮辱性的语言,那么就将该留言标识为内容不当.过滤这类内容是一个很常见的 ...

  7. .net解决js访问服务器端,跨域访问的问题

    在Global.asax.cs文件中,添加 protected void Application_BeginRequest(object sender, EventArgs e) { HttpCont ...

  8. c# 操作word demo

    /// <summary> /// 新创建word /// </summary> /// <param name="fileSaveDirectory" ...

  9. python 日历

    上章总结了python中time模块的使用,这次总结日历模块 calendar >>> import calendar >>> cal = calendar.mon ...

  10. 5. JavaScript 正则表达式

    1. 概念 正则表达式(英语:Regular Expression,在代码中常简写为regex.regexp或RE)使用单个字符串来描述.匹配一系列符合某个句法规则的字符串搜索模式. 2. 使用字符串 ...