Creating your own header file in C

Posted 牛顿的小脑

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Creating your own header file in C相关的知识,希望对你有一定的参考价值。

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

 

参考: 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的主要内容,如果未能解决你的问题,请参考以下文章

css 简单网格 - http://j4n.co/blog/Creating-your-own-css-grid-system

css 简单网格 - http://j4n.co/blog/Creating-your-own-css-grid-system

Paddle your own canoe.

Design Your Own Protocol In Five Minutes

Build your own distribution based on Fedora CoreOS

Build your own distribution based on Fedora CoreOS