Library Functions in C - C tutorials

                                     Library Functions ::-

C tutorials
library


C language has lot of valuable library functions which is used to carry out some tasks

for instance printf function is used to print output on screen.

The built-in functions known as library functions are gathered in one place and given the name library.

Here, each function carries out a certain action. To obtain the pre-defined output, we can use the library functions.

Many header files are used to declare every function in the C standard library. These library functions were developed when compilers were being designed.

Using #include<filename.h>, we include the header files in our C application. The relevant files are added to the C program each time it is run and executed.

Features of Header Files:-

The following are a few of the header file's functions:

The standard input/output header file, stdio.h, contains declarations of input/output functions.

the conio.h This file is an input/output header for the console.

All functions relating to strings can be found in the header file string.h.

STD LIB.H Common functions that are used in C programmes can be found in this file.

math.h − This header file contains all math-related functions.

time.h − The functions relating to time and the clock are in this file. constructed in stdio.h

Ex.  printf("%d",i);


Constructed in stdio.h :-

Printing all char, int, float, text, etc., values to the output screen is done using the printf() method. scanf()

Data from the keyboard is read using this function.

getc() :-
reads characters out of a file.

get() :-
obtains a line from the keyboard using 

getchar() :-
The function reads characters from the keyboard.

puts() :-
 prints a line to the output screen.

putchar() :-
Writes a character to the screen using.

fopen() :-
All file handling routines are defined in stdio, including.

header file in h :-

💥 A file opened by fopen() is closed.

💥 getw() reads an integer from a file.

💥 Writes an integer to a file using putw().

💥 Reads a character from a file using fgetc().

💥 putc() records a character in a file.

💥 Writes a character to a file using fputc().

💥 One line at a time, fgets() reads a string from a file.

💥 f puts() records a string in a file.


👉%d  for integer

👉%f   for float or real value

👉%c  for character 

 C output functions :-

For performing output operations, the C programming language includes built-in functions. Data is shown using output procedures on a user screen (output screen), a printer, or in any type of file. The following built-in output functions are available in the C programming language.

On the output screen, the printf() function is used to print strings, data values, or a combination of strings and data values (User screen). The "stdio.h" header file contains a built-in function called printf(). The #include declaration must be used to include the appropriate header file (stdio.h) when utilising the printf() function in a programme. The syntax for the printf() function is as follows:

Syntax :-

printf("welcome in my blog!!");

Receiving input from user ::-

C Input Methods :-

For performing input operations, the C programming language includes built-in functions. The keyboard's user values (input) are read via the input procedures.The following input functions are included by default in the C programming language.


the functions are: 
 getchar(),
 getch(), 
 gets() ,
 fscanf() ,
 scanf().

Scanf Function :-

To read several data values of various data kinds from the keyboard, use the scanf() function. The "stdio.h" header file contains the definition of the built-in scanf() function. When using the scanf() function in our programme, we must use the #include command to include the corresponding header file (stdio.h). 

The syntax for the scanf() function is as follows:

In order to get input from user and assign it to variable we use scanf function.

syntax :-

scanf("format strings",&variableNames);

Note : -  & is "address of" operator assign to variable. 

 getchar() function :-

A character from the keyboard is read and returned to the programme using the getchar() function. One character can be read using this function. We must either write several times or use a looping statement to read multiple characters.

 getch() method :-

Similar to the getchar function is the getch() method. A character from the keyboard is read and returned to the programme using the getch() method. One character can be read using this function. We must either write several times or use a looping statement to read multiple characters.

gets() function :-

To read a line of text and store it in a character array, use the gets() function. The gets() function reads a line of characters or a string until a newline symbol appears.

 fscanf() function :-

With the idea of files, one uses the fscanf() function.the fscanf function is used to read data from file. when we used fscanf() function file must be in reading mode.

Standard C library functions :-

Function            system include file        function prototype             Description

abort                   stdlib.h                          voidabort(void);                stop a program 
                                                                                                               abnormally.

abs                       stdlib.h                          int abs(int n);                   calculates an integer                                                                                                                  input n's absolute                                                                                                                       value.

acos                      math.h                         double acos(double x);      calculate arc cosine                                                                                                                   of x. 

asctime                 time.h                         char *asctime                      transforms a                                                                                 (const struct tm * time);    structure that                                                                                                                            contains the time into                                                                                                                  a character string.  






No comments

This website is only for educational purpose, it is not related to any organization. This website helps to beginners in programming to learn fast.

Powered by Blogger.