Discussion:
A6P1: How to link and view separate files
(too old to reply)
Anandh Sridharan
2010-10-31 02:31:08 UTC
Permalink
I currently have the code for Part 1 complete, but they are all on one
file. How do I break up this file into the main, the .h file and
the .c file containing the functions? Also how do I use gcc to link
these files together?
Thank you for any help!
David Xingliang Lou (CS 137 Tutor)
2010-11-01 14:14:06 UTC
Permalink
Post by Anandh Sridharan
I currently have the code for Part 1 complete, but they are all on one
file. How do I break up this file into the main, the .h file and
the .c file containing the functions? Also how do I use gcc to link
these files together?
Thank you for any help!
Hi Anandh

This was actually covered during lecture. The Thursday lecture right
before midterms, in fact.

Put all your declarations in the .h file. This includes your struct
fraction, as well as the 6 function declarations.

Put all the function definitions in the .c file. #include the .h file at
the top.

And finally, put your main program in a separate .c file. Again,
#include the .h file.

To compile it, type gcc fraction.c main.c (if your test program is
called main.c)

Loading...