码迷,mamicode.com
首页 > 其他好文 > 详细

Creating your own header file in C

时间:2016-12-21 11:34:41      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:using   str   tin   print   .com   sar   targe   ini   target   

终于跑起来了,含自定义 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

标签:using   str   tin   print   .com   sar   targe   ini   target   

原文地址:http://www.cnblogs.com/oxspirt/p/6207053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!