×

Stdio.h in C

Header files are used to make the programmer’s efforts a lot easier. In order to make the programming simple, there are a number of libraries which are included as predefined functions in C language. Header files are used to contain these predefined standard library functions.

Each and every one of the header files has a particular function. Any of the header files can be included in a program. Stdio.h is a header file provided by the C language. It stands for standard input output. Functions that are used to deal with input and output are declared in the stdio.h header file.

Syntax of stdio.h in C

 #include<stdio.h>

Here, the “#include” is the preprocessing directive which is used to insert a particular header file from another file. The “.h” is an extension that can be found on all the header files. The content of a header file can be used by including it in a program.

Functions that are used to deal with the standard input and output are listed in the stdio.h header file. fdopen() is one of these functions which is only supported in POSIX program.

There are more than 40 functions contained in the stdio.h header file that are used to perform input and output operations, due to this we get a lot of different methods to input and display data in C. It is also one of the most commonly used header files in C language. It is a built-in header file.

For example, we can use the functions printf() and scanf() to display output and get input from the user. The communication with users becomes easier due to this library.

A communication channel between the program and the actual input and output devices is known as stream. In the stdio.h library these streams are used to communicate with the physical devices. A stream that is used to display output on a monitor is called as standard output (stdout).

There are a great number of functions declared in this library. Some of these are given in the following table:

fopen()getc()perror()ferror()feof()
freopen()rename()fseek()clearer()setbuf()
gets()fflush()fupdate()fldata()tmpfile()
putc()flocate()sprintf()fgetpos()tmpnam()

Defined types in stdio.h

To gain access to a particular stream, stream functions make use of a pointer to the FILE type. Stdio.h is where the FILE type is defined. The information provided in the FILE structure is used by the system to maintain the stream. Some of the C standard streams are also defined in the stdio.h, like stdin(), stdout() and stderr().

In order to determining error information in the event of an I/O function failure stdio.h defines the type’s__amrc_type and __amrc2_type.

In stdio.h, the type fldata_t is defined for the fldata() function.

Other types like __S99parms, __S99rbx_t, and __S99emparms_t are defined in stdio.h for use with the svc99() function.

For use with fgetpos() and fsetpos(), stdio.h defines the type fpos_t.

Library variables in stdio.h

In the stdio.h library, there we have three variables (or types). These 3 variables are given in the following table:

Variable Description
FILEThe information about controlling streams is stored in this data object.
size_tThis is the return type of sizeof operator and is an unassigned integral data type.
fpos_tIt is used to represent any position in the file.

A basic example of use of stdio.h in C is shown below:

Example:

#include<stdio.h>
int main(){
	intnum;
	printf(“Enter the number:”);
	scanf(“%d”,&num);
	printf(“The entered number is : %d  “,num);
	return 0;	
}

Output:

Enter the number: 5
The entered number is: 5

Stdio.h Macros

Just like the library variables, the stdio.h library also contains macros. Macros are the name given to a small piece of code. Some of stdio.h library’s commonly used macros are given below:

S.NO.MacroDescription
1.FOPEN_MAX()This macro is an integer that represents the maximum number of files that the system can guarantee to be opened simultaneously.
2.FILENAME_MAX()A filename's maximum number of characters. It can be used to specify an array's size (for holding, for instance, the filename returned by fldata()).
3.EOF()It specifies the value that an I/O function returns when it finds the End of File (EOF) or, in some cases, an error.
4.BUFSIZ()When allocating buffers for stream I/O, this value is the expected size of the user's buffer that is supplied to setbuf(). It is the buffer size that will be used by the setbuf() library function. z/OS XL C/C++ applications will not use the user's buffer if a larger buffer is required.
5.NULL()A NULL Pointer i.e. a pointer that does not point to anything.
6.L_tmpnam()It contains an integer that represents the size of the longest temporary name that can be generated by the tmpnam() function.
7.TMP_MAX()This macro is the maximum unique filenames the tmpnam() function can generate.

Related Topics

How to create a node in C?

A node is a small concept taken from the graph theory, or a node is a fundamental unit of a data structure, like a tree data structure. Every graph contains...

3 minutes read.

Type qualifiers in C

Type qualifiers in C: In the C programming language, type qualifiers are the keywords that prepend to the variables to change their accessibility, i.e., we can tell that the type...

4 minutes read.

gets() function in C

gets() is a pre-define or built-in function present in the stdio.h header file. stdio stands for standard input and output. gets() function is used to read a stream and store...

4 minutes read.

Heap Sort in C

In this tutorial, we will learn about heap sorting in C language, but before going to Heap sort, we have to know the concept of Complete Binary Tree. What is Complete...

8 minutes read.

Bubble sort in C

Bubble sort in C Bubble sort is defined as the algorithm that is used for the sorting mechanism. It follows the technique of replacing the first index with the more minor...

4 minutes read.

getch() function in C

getch() is a pre-define or built-in function present in the conio.h library. It returns the given character immediately without waiting for the enter key to be entered. By using getch()...

3 minutes read.

Unformatted input() and output() function in C

Unformatted Input and Output functions take the character, character array, and strings as input. We can read-only character data types with these functions. These functions are already defined in the...

5 minutes read.

#include in C

In the C programming language, #include is another way of inferring a standard, or a user defines file into the application or program. The preprocessor of the programming standard generally...

4 minutes read.

Add two numbers using the function in C

Here we will learn how to add two numbers by creating function in C. Let’s learn this with help of example. Code: - #include <stdio.h> int add_two_no(int a, int b); int main(){   int first_num,...

1 minute read.

Nested if-else statement in C

If we use an if-else statement within another if statement in a C program, it is called a nested if-else statement in C. It helps to check the condition inside...

3 minutes read.

Recursion in C

Recursion in C: In the C programming language, the concept known as recursion exists that is a technique in which a function calls itself either directly or indirectly. It allows...

4 minutes read.

Flow Chart of Do while loop in C

This is a flowchart that represents the process of executing the Do while loop in the C programming language Generally, as we know there are three main components of Do While...

3 minutes read.

Fahrenheit to Celsius in C

Before going into conversion, we have to know what Fahrenheit and Celsius mean, these are both units to measure the temperature.In our daily life, we use both Fahrenheit and Celsius,...

1 minute read.

Character Class Tests in C

Introduction The <ctype.h> is a header file in C which is used to declare functions for testing characters. This header file of the C standard library is used to declare multiple...

4 minutes read.

Tower of Hanoi in C

What is Tower of Hanoi? The Tower of Hanoi is a gaming problem that was created in 1883 by a French mathematician named Édouard Lucas. The Tower of Hanoi temple in...

4 minutes read.

Entry Control Loop in C

Initially, an entry control loop verifies the termination condition at the entry point. After that, its control passes to the main body of the while or for loop if the...

3 minutes read.

Merge Sort in C

The merge sort follows the principle of the divide and conquers algorithm. Firstly it divides the input of an array into two halves and then calls itself for the two...

4 minutes read.

Ceil and Floor in C

In arithmetic, a rational number is a number that can be expressed as the quotient p/q of two integers. Where q is zero. The set of rational numbers includes all...

6 minutes read.

Pi() Function in C

Pi: Mathematic constants are not defined in the c or c++ programming languages. To use the Mathematical constants firstly, we have to define the _USE_MATH_DEFINES and then declare the cmath and...

3 minutes read.

How to use atoi() function in C

Introduction: The atoi() is a function used in C programming language. This function converts string characters to the integer value. The atoi() function converts the input string to the return type of...

4 minutes read.