×

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

C –Structure

C structure is a collection of different types of data that is grouped together. It is used to represent records.Structkeyword is used to create a structure. Each element of a...

1 minute read.

Bit Fields in C

The size of a structure in C is specified in bits. The primary goal of it is to use memory efficiently, once we understand that a bit's value must fall...

3 minutes read.

How to Calculate Time Complexity in C?

What is time complexity? An algorithm's time complexity measures how long it takes to complete a task in relation to the size of the input. It should be noted that the...

5 minutes read.

Use of free() function in C

Introduction The free() function uses in C programming language. The free() function in the C programming language uses to release or deallocate the memory blocks; these blocks are previously allocated by calloc(), malloc() or realloc()...

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.

C Decision control statement

Decision Making C conditional statements are used to specify one or more conditions. The statements will be executed if the condition becomes true otherwise alternative statement will be executed if the...

3 minutes read.

fflush in C

In this article, we will understand what is fflush(), the need for fflush and fflush(stdin), and fflush(stdout). The fflush() function is used to clear the output buffer and move the buffered...

3 minutes read.

Type Casting in C

Type casting is a way to convert a variable from one data type to another data type.Syntax: (type) expression;     Example: #include <stdio.h> int main() { int a,b; float sum; printf("Example of Type Casting\n"); printf("Enter any integer nos:"); scanf("%d",&a,&b); sum=a+b; printf("Sum: %f",sum); return 0; } Output Example...

1 minute 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.

Array Example in C

An array is a collection of similar types of data elements arranged in such a way that any number of values can be assigned to it. It can store values that...

4 minutes read.

Find out Power without using POW function in C

Introduction: In this discussion, we will discuss how we find out power without using the POW function in C. In this article, you'll understand how to compute integer powers in...

3 minutes read.

Runtime vs compile time in C

In the C programming language, the often used terms in every step consist of compile time and runtime. The compile time is referred to the source code that will be...

4 minutes read.

Fee Management System in C

The concept is to split every operation into its very own characteristic. Software is made from all of the capabilities mixed with transfer cases. An example of the capabilities may...

5 minutes read.

Two-Dimensional array in C

What is an Array? The collection of a fixed number of elements of homogeneous data types that are stored in contiguous locations in the memory is known as an array. Only...

6 minutes read.

How to get ASCII value in C

For text data on computers and the internet, ASCII (American Standard Code for Information Interchange). It is the most widely used character encoding standard. One hundred twenty-eight alphabetic, numeric, special...

3 minutes read.

Prime Number code in C

Prime Number Programs in C language In this tutorial, we will learn how to check whether the given number is a prime number or not, and how to print all the...

4 minutes read.

Limitations of Inline Function in C

The compiler is unable to conduct inlining in two instances. It just accepts the inline definitions and produces space for the function in the same way it does for a...

3 minutes read.

Decimal to Binary in C

What is a decimal number? A decimal number is a number represented in the decimal number system. This system of binary conversion uses base 10 to represent numbers, i.e. the digits...

3 minutes read.

User Defined Functions in C

C Functions: A function is defined as a block of code that is used to perform some specific task. In functions, we use flower brackets ({}) which contain the set of programming...

5 minutes read.

How to measure time taken by a function in C?

Measuring the time taken by a function is quite a complex task, because numerous methods are frequently not transferable to other platforms, measuring the execution time of a C programs...

5 minutes read.