Multi-file programs

This is a discussion on Multi-file programs within the C Programming forums, part of the General Programming Boards category; I'm still a bit new at making programs... Could someone explain to me exactly how to put functions in separate ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    1

    Multi-file programs

    I'm still a bit new at making programs... Could someone explain to me exactly how to put functions in separate files from the one containing main()? Thanks.

  2. #2
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Quote Originally Posted by Lord Xela
    I'm still a bit new at making programs... Could someone explain to me exactly how to put functions in separate files from the one containing main()? Thanks.
    The actual mechanics of it can vary from compiler to compiler. I work primarily on Linux, using gcc and make, but I know there are IDEs on Windows that let you drag/drop files into project folders etc.

    Basically though, what you're looking to do is have a file, say a.c, that has your main function. In that file, you will include b.h -- b.h contains the function declarations for your other source file (call it b.c) that contains your function code.

    Now, you want to build all that together. You basically compile b.c into an object file (b.o) and then make sure that you link that object file in when you compile and link a.c

    It is hard to describe that last part without getting compiler specific

    Hope that's a help....

    (If not, at least it is a starting point for others to work off of.....)
    Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    134

    Smile

    Hi,

    'fgw' is very right about the concept. that is the proper way of doing things.

    But as u r a beginner. u can use one thing also. write functions in different files. like a.c, b.c and c.c are three different files containing two- two functions in each.

    now Main.c is ur main file. include these a.c, b.c and c.c file in Main.c with proper path. and use those function in main().

    Code:
    #include "path/a.c" 
    #include "path/b.c" 
    #include "path/c.c"
    I dont know what does C standard say about this, but it will work.
    S_ccess is waiting for u. Go Ahead, put u there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File being filled with NULLs
    By Tigers! in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2009, 06:28 PM
  2. Error when loading 3ds file
    By The Wazaa in forum C++ Programming
    Replies: 6
    Last Post: 01-24-2006, 08:27 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 09:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

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