C Program to Find Total of Even Integers

C Libraries – Quick Guide

Everyone knows core of the C language is small and very simple to use, and special functionality is provided in the form of libraries of ready-made functions. Some of C libraries are provided for you, giving you access to many special abilities without needing to reinvent the wheel. You can also make your own, but to do so you need to know how your operating system builds libraries.

C Libraries are files of ready-compiled code which we can merge with a C program at compilation time. Each library comes with a number of associated header files which make the functions easier to use.

For example, there are libraries of mathematical functions, string handling functions and input/output functions and graphics libraries. It is up to every programmer to make sure that libraries are added at compilation time by typing an optional string to the compiler.

cc -o program_name prog.c –lm

when you compile the program. The ‘-lm’ means: add in ‘libm’. If we wanted to add in the socket library ‘libsocket.a’ to do some network programming as well, we would type


cc -o program_name prog.c -lm –lsocket

These C libraries are not included automatically because it would be a waste for the compiler to add on lots of code for maths functions, say, if they weren’t needed. When library functions are used in programs, the appropriate library code is included by the compiler, making the resulting object code often much longer.

C Libraries with Examples

C Libraries are supplemented by header files which define macros, data types and external data to be used in conjunction with the libraries. Once a header file has been included, it has effectively added to the list of reserved words and commands in the language. You cannot then use the names of functions or macros which have already been defined in libraries or header files to mean anything other than what the library specifies.

The most commonly used header file is the standard input/output library which is called ‘stdio.h’. This belongs to a subset of the standard C library which deals with file handling. The ‘math.h’ header file belongs to the math- ematics library ‘libm.a’. Header files for libraries are included by adding to the source code:

#include header.h

at the top of a program file. For instance:

#include "myheader.h"

includes a personal header file which is in the current directory. Or

#include <stdio.h>

includes a file which lies in a standard directory like ‘/usr/include’. The #include directive is actually a command to the C preprocessor, Some functions can be used without having to include library files or special libraries explicitly since every program is always merged with the standard C library, which is called ‘libc’

#include <stdio.h>
main ()
{
printf ("C standard I/O file is included\n");
printf ("Hello world!");

The program wishing to use a mathematical function such as cos would need to include a mathematics library header file.

#include <stdio.h>
#include <math.h>
main ()
{ double x,y;
y = sin (x);
printf ("Maths library ready");
}

The particular operating system might require its own special library for certain operations such as using a mouse or for opening windows in a GUI environment, for example. These details will be found in the local manual for a particular C compiler or operating system.

Online Training Tutorials

  • C Program to Find Total of Even IntegersC Tutorial – Learn C Programming Language TutorialLearn C programming is very easy if you follow our popular C tutorial which will take you from the beginning of C programming. This C tutorial is mainly designed for beginners and […]
  • sap tipsSAP Tips & TricksList out some of the SAP Tips & Tricks 1), Do you know what entering /n in the Command Line will do? Entering /n in the Command Line followed by a transaction code, e.g IE03 […]
  • sap Project systemsSAP Project Systems – Step by Step ConfigurationSAP Project Systems are generally part of the internal processes of a individual company. This will be able to control all tasks in project execution, AS this case you need an […]
  • credit managementHow to Configure Credit Management in SAP?All business have their own credit management needs, SAP allows you to specify your own automatic credit checks based on a variety of criteria. You can also specify at which critical […]
  • SAP NetWeaverWhat is SAP NetWeaver?SAP NetWeaver, the next evolution of mySAP Technology integrates information and business processes across technologies and organizations. What's more, SAP NetWeaver embraces Internet […]
  • ABAP programsDifferent Types of ABAP ProgramsDifferent Types of ABAP programs : ABAP, there are 7 different types of ABAP programs which includes executable, function module, module pool, subroutine, class, interface, Types of ABAP […]
  • SAP InstallationSAP InstallationSAP Installation process could sound confusing at first look. Key to success is reading and then following. Documentation provided by SAP is excellent. If you are planning to install […]
  • ABAP Package ConceptABAP Package Concept an OverviewABAP Package Concept, ABAP applications server’s one of the most important innovations is ABAP package concept, owing to the reason that it allows the development of software considered to […]