Thursday 5 December 2019

C Tutorial - Header File and Library Functions Uses

Header file

Introduction

The C provides a large number of C functions as libraries. Some of these implement frequently used operations, while others are very specialized in their application.

Wise programmers will check whether a library function is available to perform a task before writing their own version.

This will reduce program development time. The library functions have been tested, so they are more likely to be correct than any function which the programmer might write.

This will save time when debugging the program. For using these files ,certain files are needed to be included in the program which make call to these functions.

These files are known as Header files and they contain macro definition ,type definition, and function declarations.

These header files usually have an extension .h as stdio.h, ctype.h, string.h, math.hstdlib.h, stdarg.h, time.h etc.


Use of library functions

To use a function, ensure that you have made the required #includes in your C file. Then the function can be called as though you had defined it yourself.

It is important to ensure that your arguments have the expected types; otherwise the function will probably produce strange results.

Some libraries require extra options before the compiler can support their use.

For example, to compile a program including functions from the math.h library the command might be cc mathprog.c -o mathprog –lm

The final -lm is an instruction to link the maths library with the program. The manual page for each function will usually inform you if any special compiler flags are required.

Some Useful library functions

There is a vast collections of function .Some of them are grouped together and listed below.

String Function:

strcpy
copies one string into another.
strcat
appends one string to another.
strcmp
compare one string to another.
strcmpi
compare one string to another without case sensitive.
strlen
calculates the length of a string.
strrev
reserve a string.

Mathematical Function:

abs
returns absolute value of an integer.
sin
calculate the sine.
cos
calculate the arc cos.
tan
calculate the arc tangent.
acos
calculate the arc cosine.
asin
calculate the arc sine.
atan
calculate the arc tangent.
ceil
rounds up.
floor
rounds down.
log
calculate the natural logarithm of x.
pow
calculate x to the power of y.
sqrt
calculate the positive square root of input value.

Date & Time  Function:

asctime
converts date and time to ASCII.
clock
determine process time.
getdate
gets system date
gettime
gets system time.
setdate
sets DOS date
settime
sets system time.
time
gets time of day.

Utility Function:

abort()
abnormally terminates a process.
bsearch()
binary search of an array.
tolower()
translate character to lower case.
toupper()
translate character to upper case.
qsort()
sorting using the quick sort algorithm.
exit()
terminate execution of a program.
free()
frees allocated block.

Character Class Test Functions:

isupper()
check and returns non-zero if c is an upper case letter (A-Z).
islower()
check and returns non-zero if c is a lower case letter (a-z).
isspace(()
check and returns non-zero if c is a space tab, carriage return, newline, vertical tab, form feed etc.
isascii()
tests whether a character is an ASCII (0 to 127) character.
isalpha()
check and returns non-zero if c is a letter (A-Z or a-z).
iscntrl()
tests whether a character is a control character.
toascii()
translate character to ASCII format.
tolower()
translate character to upper case.


Previous Page                                      First Page

More Topics:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...