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 optimized 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.
- Readability : 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
|Used to verify assumptions made by the program and print 0 if the assumption is false
|Console input-output header
|Used to perform console input and output operations from the keyboard
|Character type header
|Used to declares a set of functions to check individual characters
|Error handling header
|Used to define macros for reporting and retrieving error conditions using the keyword “errno”
|Used to perform localization functions to set locale and get locale using setlocale() and localeconv() functions respectively
|Used to declare a set of functions to perform mathematical operations
|Used to perform jump functions
|Used to perform signal handling functions to install signal handler and to raise the signal in the program using signal() and raise() functions respectively
|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
|Standard Input/Output header
|Used to perform input and output operations using scanf() and printf() functions respectively
|Standard library header
|Used to perform standard utility functions using malloc() and calloc() to dynamically allocate memory
|Used to perform string manipulation operations
|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
|Used to clear the output screen
|Used to read character from keyboard
|Used to read character from keyboard and echo to the output screen
|Used to change the text color
|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
|Used to check alphanumeric character
|Used to check whether a character is an alphabet or not
|Used to check control character
|Used to check numeric character
|Used to check graphic character
|Used to check lowercase alphabet
|Used to check printable character
|Used to check punctuation
|Used to check white-space character
|Used to check uppercase alphabet
|Used to check hexadecimal digit character
|Used to convert alphabet to lowercase
|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 used to report the cause of error
|Used to represent the domain error for a function call
|Used represent range error
|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.
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.
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.
|Used to returns nearest integer value which is greater than or equal to the argument passed to that function
|Used to calculate cosine
|Used to calculate hyperbolic consine
|Used to calculate the exponential “e” to the xth power
|Used to returns the nearest integer which is less than or equal to the argument passed to this function
|Used to calculates natural logarithm
|Used to calculates base 10 logarithm
|Used to find the power of the given number
|Used to round of an floating number to its nearest integer value.
|Used to calculate sine value
|Used to calculate hyperbolic sine
|Used to calculate tangent
|Used to calculate hyperbolic tangent
|Used to trucate of trim the decimal value from floating point value and returns integer value