Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
What are the C library functions?
Library functions are built-in functions that are grouped together and placed in a common location called library. Each function performs a specific operation, allowing us to get pre-defined outputs without implementing complex logic from scratch.
All C standard library functions are declared by using many header files. These library functions are created at the time of designing the compilers.
We include the header files in our C program by using #include<filename.h>. Whenever the program is compiled and executed, the related files are included in the C program.
Syntax
#include <header_file.h>
int main() {
// Use library functions here
return 0;
}
Common Header Files
Here are the most commonly used header files in C programming −
-
stdio.h − Standard input/output header file where I/O functions are declared
-
string.h − All string manipulation functions are in this header file
-
stdlib.h − Contains general utility functions like memory allocation, process control
-
math.h − All mathematical functions like sin(), cos(), sqrt() are declared here
-
time.h − Contains time and date manipulation functions
Example: Using Library Functions
Here's a simple program demonstrating the use of various library functions −
#include <stdio.h>
#include <string.h>
#include <math.h>
int main() {
char name[50] = "TutorialsPoint";
int length;
double result;
// Using stdio.h functions
printf("Website: %s<br>", name);
// Using string.h functions
length = strlen(name);
printf("Length: %d<br>", length);
// Using math.h functions
result = sqrt(25.0);
printf("Square root of 25: %.2f<br>", result);
return 0;
}
Website: TutorialsPoint Length: 14 Square root of 25: 5.00
Key stdio.h Functions
The stdio.h header contains essential input/output functions. Here are the most commonly used ones −
| Function | Description |
|---|---|
| printf() | Prints formatted output to console |
| scanf() | Reads formatted input from keyboard |
| getchar() | Reads a single character from keyboard |
| putchar() | Writes a single character to console |
| fopen() | Opens a file for reading/writing |
| fclose() | Closes an opened file |
| fgets() | Reads a string from file |
| fputs() | Writes a string to file |
Conclusion
C library functions provide pre-written, tested code for common programming tasks. Using appropriate header files like stdio.h, string.h, and math.h saves development time and ensures reliability in your programs.
