I've got this small app , from 2 .c files. One file contains the main
and the other file contains functions used in the main. I compile this
using gcc like this: gcc -c *c && gcc -o app *o. But I want to do it in
an other way. I want to use header files I've googled but did not find
anything usefull expect that there should be prototypes in my header
file can anyone help me ? 36 3301
On Sat, 15 Nov 2003 11:52:28 +0000, Geiregat Jonas wrote: I've got this small app , from 2 .c files. One file contains the main and the other file contains functions used in the main. I compile this using gcc like this: gcc -c *c && gcc -o app *o. But I want to do it in an other way. I want to use header files I've googled but did not find anything usefull expect that there should be prototypes in my header file can anyone help me ?
It's not clear what you are talking about.
Try this:
gcc -o app *.c
Geiregat Jonas wrote: I've got this small app , from 2 .c files. One file contains the main and the other file contains functions used in the main. I compile this using gcc like this: gcc -c *c && gcc -o app *o. But I want to do it in an other way. I want to use header files I've googled but did not find anything usefull expect that there should be prototypes in my header file can anyone help me ?
I will do a small example.
main.c
------
#include <stdio.h>
#include "calc.h"
int main()
{
int x;
printf("Enter an integer: ");
scanf("%d", &x);
printf("The square of %d is %ld\n", x, square(x));
return (0);
}
calc.h
------
#ifndef CALC_H
#define CALC_H
long square(int);
#endif
calc.c
------
#include "calc.h"
long square(int x)
{
return ((long) x * x);
}
---------
NOTES
notice the quotes when including calc.h because it is in the same
directory as the source file
also, if you've never used preprocessor directives, the "#ifndef
CALC_H" may look confusing. You want this in the header file, though.
It prevents multiple inclusions of that header file. Just change CALC_H
to whatever.. I dont think it matters as long as its the same as the
#define statement below it.
HTH,
Aaron
Look at an article at this link.
It is good simple tutorial on C programming and also there detailed
instructions how to make library at 'libraries' link using gcc
compiler. (I've done that and it worked). http://computer.howstuffworks.com/c.htm
tuchka
tuchka wrote: Look at an article at this link. It is good simple tutorial on C programming and also there detailed instructions how to make library at 'libraries' link using gcc compiler. (I've done that and it worked).
http://computer.howstuffworks.com/c.htm
The first incorrect statement I spotted was at http://computer.howstuffworks.com/c1.htm
Here it is:
"C is what is called a compiled language. This means that once you write
your C program, you must run it through a C compiler to turn your program
into an executable that the computer can run (execute)."
The second, related error:
"...to write and run a C program, you must have access to a C compiler."
The third error:
"When you enter this program, position #include so that the pound sign is in
column 1 (the far left side). Otherwise, the spacing and indentation can be
any way you like it."
Counter-example:
#include<stdio. h>intmain(){p r i n t f("This is output from my first
program!\ n"); return0;}
When Mr Brain has fixed those errors, I'll find some more for him to do.
--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Richard Heathfield <do******@addre ss.co.uk.invali d> scribbled the following: tuchka wrote: Look at an article at this link. It is good simple tutorial on C programming and also there detailed instructions how to make library at 'libraries' link using gcc compiler. (I've done that and it worked).
http://computer.howstuffworks.com/c.htm
The first incorrect statement I spotted was at
http://computer.howstuffworks.com/c1.htm
Here it is:
"C is what is called a compiled language. This means that once you write your C program, you must run it through a C compiler to turn your program into an executable that the computer can run (execute)."
I don't see how that statement is incorrect.
The second, related error:
"...to write and run a C program, you must have access to a C compiler."
Hmm, I can see two ways to parse that as erroneous.
1) If writing a program merely consists of writing the source code,
you don't need a compiler.
2) You don't need *any* programming tools to run programs.
But does "to write and run a C program" mean "to write a C program
and then to run the same C program" or "to write a C program, and
to run (possibly another) C program"?
(snip third error)
When Mr Brain has fixed those errors, I'll find some more for him to do.
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You can pick your friends, you can pick your nose, but you can't pick your
relatives."
- MAD Magazine
Richard Heathfield wrote: http://eic.sourceforge.net/ is one of several counter-examples.
This is most excellent ;) I didn't know they had C interpreters now.. heh.
In <t%************ **********@twis ter.tampabay.rr .com> Aaron Walker <ka*****@REMOVE THIScfl.rr.com> writes: Richard Heathfield wrote: http://eic.sourceforge.net/ is one of several counter-examples.
This is most excellent ;) I didn't know they had C interpreters now.. heh.
They've been around for quite a while.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steven T. Hatton |
last post by:
If a header is not necessarily a source file, and the sequences delimited by
< and > in header names aren't necessarily valid source file names, what
exactly is a header?
--
p->m == (*p).m == p.m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
|
by: Johannes Bauer |
last post by:
Hi group,
I've got a question concerning inclusion of .hpp files. Currently I'm
including all needed header files in the .cpp file. This means all
dependencies of the package and all dependencies of these dependencies
and so on.
This is quite ugly.
A start of an "Example.cpp" file could look like this
|
by: Bob |
last post by:
Hi,
I am trying to use BULK INSERT with format file. All of our data has
few bytes of header in the data file which I would like to skip before
doing BULK INSERT.
Is it possible to write format file to skip these few bytes of
header before doing BULK INSERT? For example, I have a 1 GB data file
with 1000 byte header. Except for first...
|
by: pooja |
last post by:
Suppose i have created a class c1 with f1()in c1.cpp
and included this c1.cpp in file1.cpp file , which is also having
main() by giving the statement #include "c1.cpp".
the same i can do by using header file. i can create a class c1 with
f1() in c1.h and include this c1.h in file1.cpp by giving the statement
#include "c1.h"
tell me that...
|
by: alan |
last post by:
Dear all,
I have written my own function by C. And my development platform is
W2k with VC6.0.
Then I also defined a header file to extern declare this function.
After that, I include this header file.
The function is stored in C:\temp\myfun.c
int func(){
return 1;
| |
by: Sujan Datta |
last post by:
What are the possible effects of modifying an existing header file,
which includes bunch of defines, function prototypes and some struct
definitions. The structure of the header file looks something like
this
//Start of header
Define
Define
Define
Define
|
by: Derrick Coetzee |
last post by:
It seems like, in every C source file I've ever seen, there has been a
very definite include order, as follows:
- include system headers
- include application headers
- include the header associated with this source file
For example, in a file hello.c:
#include <stdio.h>
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen. It is
almost like it is trying to implement it's own COM interfaces...
below is the header, and a link to the dll+code:
Zip file with header,...
|
by: The Cool Giraffe |
last post by:
Please note that i do intend to use a header file. However,
i'm not sure if it's really needed or just a convention.
Suppose we have the following two files.
// Something.h
class Something {
private: int number;
public:
Something ();
|
by: Ramon |
last post by:
Is there a way to initialize the variables (or other data) of a header
file by using a function (similar to main() function)??
Thankx
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |