Creating your own header file in C

Source: Internet
Author: User

Finally ran up, with custom include. h C language Program, Super happy!

Reference: Http://stackoverflow.com/questions/7109964/creating-your-own-header-file-in-c

Down vote

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 */< Span class= "Typ" >int Main (void{ int y = Foo (3/* use the function here */ Printf ( "%d\n" Span class= "pun" >, Yreturn 0;                /span>                

To compile using GCC

gcc -o my_app main.c foo.c

Creating your own header file in C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.