C Standard Library
In this tutorial, we will learn about the different standard library functions and their used in C programming.
Standard Library Functions
Standard library functions or simply C Library functions are inbuilt functions in the C compiler which make the code shorter and easy to read.
There are many inbuilt functions are defined in each header file.
For example, <stdio.h> header includes the functions like printf(), scanf(), etc. We cannot use these functions without importing the <stdio.h header file.
Note : We cannot use a predefined function without importing that specific header file in which it is defined.
Advantages of Using C library functions
- Faster Performance : Library Functions are optimised for better performance.
- Easy Syntax : syntax of library functions are very easy to learn and use.
- Optimization : Library functions are highly tested in different conditions which make them reliable to use.
- Readibility : Library functions make the code shorter ,more readable and save time of programmers.
- Portable : Library functions are available in all C compilers with the same meaning and serves the same purpose regardless of the operating systems we are working on.
Different Header files and their Working
Header File | Meaning | Working |
---|---|---|
<assert.h> | Assertion header | Used to verify assumptions made by the program and print 0 if the assumption is false |
<conic.h> | Console input-output header | Used to perform console input and output operations from the keyboard |
<ctype.h> | Character type header | Used to declares a set of functions to check individual characters |
<errno.h> | Error handling header | Used to define macros for reporting and retrieving error conditions using the keyword "errno" |
<locale.h> | Localization header | Used to perform localization functions to set locale and get locale using setlocale() and localeconv() functions respectively |
<math.h> | Mathematics functions | Used to declare a set of functions to perform mathematical operations |
<setjmp.h> | Jump header | Used to perform jump functions |
<signal.h> | Signal header | Used to perform signal handling functions to install signal handler and to raise the signal in the program using signal() and raise() functions respectively |
<stdarg.h> | Standard arguments header | Used to perform standard argument functions to indicate the start of the variable-length argument list and to fetch the arguments from the variable-length argument list in the program using va_start() and va_arg() respectively |
<stdio.h> | Standard Input/Output header | Used to perform input and output operations using scanf() and printf() functions respectively |
<stdlib.h> | Standard library header | Used to perform standard utility functions using malloc() and calloc() to dynamically allocate memory |
<string.h> | String header | Used to perform string manipulation operations |
<time.h> | Date & Time header | Used to perform functions related to date and time like get and modify the current date & time from system |
assert.h Header File
assert is a macro that is designed to be used like a function.
It takes an integer expression and checks the value of expression ,
If the value of expression is zero then
the assert macro writes an message and terminates the program by calling abort.
If the value of expression is
nonzero then assert macro does nothing.
conic.h Header File
conic.h header file is used to perform console input and output operations from the keyboard.
Inbuilt Functions in conic.h file
Functions | Description |
---|---|
clrscr() | Used to clear the output screen |
getch() | Used to read character from keyboard |
getche() | Used to read character from keyboard and echo to the output screen |
textcolor() | Used to change the text color |
textbackground() | Used to change text background |
ctype.h Header File
The <ctype.h> header file is used to declares a set of functions to check(and transform) individual characters.
Inbuilt Functions in ctype.h file
Functions | Description |
---|---|
isalnum() | Used to check alphanumeric character |
isalpha() | Used to check whether a character is an alphabet or not |
iscntrl() | Used to check control character |
isdigit() | Used to check numeric character |
isgraph() | Used to check graphic character |
islower() | Used to check lowercase alphabet |
isprint() | Used to check printable character |
ispunct() | Used to check punctuation |
isspace() | Used to check white-space character |
isupper() | Used to check uppercase alphabet |
isxdigit() | Used to check hexadecimal digit character |
tolower() | Used to convert alphabet to lowercase |
toupper() | Used to convert alphabet to uppercase |
errno.h Header File
errno.h header file is used to define macros for reporting and retrieving error conditions using the keyword errno.
Macro | Description |
---|---|
errno | Macro used to report the cause of error |
EDOM | Used to represent the domain error for a function call |
ERANGE | Used represent range error |
EACCES | Used to represent an error when a file cannot be opened for reading |
locale.h Header File
locale.h header file is used to perform localization functions to set locale and get locale using setlocale() and localeconv() functions respectively.
setlocale() function
The setlocale() function is used to set or query the program's current locale.
If locale is not
NULL, then the program's current locale is modified according to the arguments which determine to change a
particular part of the current locale.
If locale is NULL, the current locale is only queried not modified.
localeconv() function
The localeconv() function is used to set or read location dependent information.
math.h Header File
The math.h header file declares a set of functions to declare a set of functions to perform mathematical operations.
Function | Description |
---|---|
ceil() | Used to returns nearest integer value which is greater than or equal to the argument passed to that function |
cos() | Used to calculate cosine |
cosh() | Used to calculate hyperbolic consine |
exp() | Used to calculate the exponential "e" to the xth power |
floor() | Used to returns the nearest integer which is less than or equal to the argument passed to this function |
log() | Used to calculates natural logarithm |
log10() | Used to calculates base 10 logarithm |
pow() | Used to find the power of the given number |
round() | Used to round of an floating number to its nearest integer value. |
sin() | Used to calculate sine value |
sinh() | Used to calculate hyperbolic sine |
tan() | Used to calculate tangent |
tanh() | Used to calculate hyperbolic tangent |
trunc.(.) | Used to trucate of trim the decimal value from floating point value and returns integer value |
string.h Header File
We have already disscused about string function in previous tutorial.
Click Here, to read about string functions.
Next Tutorial
We hope that this tutorial helped you develop better understanding of the concept of Standard Library Function in C.
Keep Learning : )