Help using header files in C

This is a discussion on Help using header files in C within the C Programming forums, part of the General Programming Boards category; Hello. I'm using gcc under linux and i'd like to know if they're any guides on the net to show ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    5

    Help using header files in C

    Hello. I'm using gcc under linux and i'd like to know if they're any guides on the net to show how to use the functions within the header files so you can use them in your program without any errors and ensure you've understood what the function requires.

    Thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Essentially, the guideline is that you put a function prototype in the header file, along with any structure or type definitions that the code using the function may need.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Or if you mean the system functions, you type "man" and then the name of the function.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    5
    Quote Originally Posted by tabstop View Post
    Or if you mean the system functions, you type "man" and then the name of the function.
    Ok cool :-D. Are the manual pages very useful then when programming and are they reliable in the sense there're hundreds of files tell you how to use the linux functions in C?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    man pages are definitely useful and meaningful, and generally reliable - the commonly used functions don't change much, so you they are unlikely to be out of date.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You should also download The GNU C Library Reference Manual since they are the ones who built gcc and your c library. It's often the same as the man pages but may contain more information and is easier to follow in its presentation.

    b/t/w to use string functions:

    Code:
    #include <string.h>
    etc.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    In addition to what has been mentioned. I would recommend reviewing how other programs have incorporated these ".h" files and see how they handled these prototype definitions. That would be a good start. Learn by example I always think.... Using .h files leads to more portable and "reuse" code techniques and ideal for creating or enhancing new ADT's. But creating new ADTs would be another subject once you get past how and when to make use of header files.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 11:21 AM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 06:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21