Library Function
Library Function
in C programming.
The prototype and data definitions of these functions are present in their
respective header files. To use these functions we need to include the header
file in our program. For example,
If you want to use the printf() function, the header file <stdio.h> should be
included.
#include <stdio.h>
int main()
{
printf("Catch me if you can.");
}
Run Code
If you try to use printf() without including the stdio.h header file, you will get
an error.
To compute the square root of a number, you can use the sqrt() library
function. The function is defined in the math.h header file.
#include <stdio.h>
#include <math.h>
int main()
{
float num, root;
printf("Enter a number: ");
scanf("%f", &num);
Enter a number: 12
Square root of 12.00 = 3.46
Header File Functions
Some of the header file functions are as follows −
stdio.h − It is a standard i/o header file in which Input/output functions are declared
conio.h − This is a console input/output header file.
string.h − All string related functions are in this header file.
stdlib.h − This file contains common functions which are used in the C programs.
math.h − All functions related to mathematics are in this header file.
time.h − This file contains time and clock related functions.Built functions in stdio.h
1 printf()
This function is used to print the all char, int, float, string etc., values onto the output screen.
2 scanf()
This function is used to read data from keyboard.
3 getc()
It reads character from file.
4 gets()
It reads line from keyboard.
5 getchar()
It reads character from keyboard.
6 puts()
It writes line to o/p screen.
Sl.No Function & Description
7 putchar()
It writes a character to screen.
8 fopen()
All file handling functions are defined in stdio.h header file.
9 fclose()
Closes an opened file.
10 getw()
Reads an integer from file.
11 putw()
Writes an integer to file.
12 fgetc()
Reads a character from file.
13 putc()
Writes a character to file.
14 fputc()
Writes a character to file.
15 fgets()
Reads string from a file, one line at a time.
16 f puts()
Writes string to a file.
17 feof()
Finds end of file.
Sl.No Function & Description
18 fgetchar
Reads a character from keyboard.
19 fgetc()
Reads a character from file.
20 fprintf()
Writes formatted data to a file.
21 fscanf()
Reads formatted data from a file.
22 fputchar
Writes a character from keyboard.
23 fseek()
Moves file pointer to given location.
24 SEEK_SET
Moves file pointer at the beginning of the file.
25 SEEK_CUR
Moves file pointer at given location.
26 SEEK_END
Moves file pointer at the end of file.
27 ftell()
Gives current position of file pointer.
28 rewind()
Moves file pointer to the beginning of the file.
Sl.No Function & Description
29 putc()
Writes a character to file.
30 sprint()
Writes formatted output to string.
31 sscanf()
Reads formatted input from a string.
32 remove()
Deletes a file.
33 flush()
Flushes a file.