Results 1 to 6 of 6
I want to ask anybody who knows to answer me:
How can i make and register C library files.. Those are files which has extension .h like stdio.h , which ...
- 01-09-2012 #1Just Joined!
- Join Date
- Jan 2012
- Location
- Kragujevac, Serbia
- Posts
- 5
C programming language simple help ?
I want to ask anybody who knows to answer me:
How can i make and register C library files.. Those are files which has extension .h like stdio.h, which is standard library
I want to create (for example) sum.h
which will have some functions in it
I am not programmer beginner i know programming in BASIC, VB6,0 and PASCAL. I learned them now i am learning C so could you please help me to do this
PS : I have Xubuntu (UNIX OS) !
- 01-09-2012 #2Just Joined!
- Join Date
- Sep 2010
- Posts
- 5
Hello,
so I suggest you to find a tutorial to learn this language. I suggest you to "Teach Yourself C in 21 Days" which is quite complete as a pdf.
About your question, an example should be:
as a header:
#include<stdio.h>
int add(int a,int b);
.cpp:
#include "sum.h"
int add(int a, int b)
{
int sum = 0;
return (sum = a +b)
}
int main(void)
{
int a,b = 3;
int s = 0;
s = sum(a;b);
printf( "sum : %d",&s);
return 0;
}
- 01-09-2012 #3Just Joined!
- Join Date
- Jan 2012
- Location
- Kragujevac, Serbia
- Posts
- 5
Can you please explain that little a bit more.
Is this part of the code in .c file which is going to be compiled
#include <stdio.h>
int add(int a, int b)
and .cpp is library file ?
- 01-09-2012 #4Just Joined!
- Join Date
- Sep 2010
- Posts
- 5
Oh sorry,
well, the header contains the function' declaration. You must include it when you want to use this functions.
After, the .c (sorry, the .cpp is for C++), is the file which will be compiled.
But I really suggest you to read a tutorial about C language. It could be quite complicated sometimes..
Good luck,
Seb
- 01-09-2012 #5Just Joined!
- Join Date
- Jan 2012
- Location
- Kragujevac, Serbia
- Posts
- 5
Thank you very much, the book is great. That will do the job
- 01-10-2012 #6Linux Newbie
- Join Date
- Nov 2008
- Location
- Tokyo, Japan
- Posts
- 243
When you install the C compiler, it will automatically install the C standard library and the necessary static and dynamic linking libraries which your program must use. The command to install it in Xubuntu is:
Then, to compile your C program, you would execute this command:Code:apt-get install gcc
This simple command will automatically link the correct library files, it will automatically include the <stdio.h> and other standard library files from the default location, and will output a binary executable program called "sum".Code:gcc sum.c -o sum
When you use the apt-get install gcc command, it will install the C standard library headers in "/usr/include" directory, which is the default location. Running the "gcc" command, it will check automatically in this directory for include files listed in angle brackets like <stdio.h>, and if you include files with quotation marks, like "sum.h", it will search in the current directory for these ".h" files. If your program is spread across multiple ".c" files (for example, if you have a "sum.c" and a "sum-parser.c") then you need to specify all of the ".c" files on the command line. For example:Code:gcc sum.c sum-parser.c -o sum


Reply With Quote
