VOOZH about

URL: https://www.geeksforgeeks.org/c/formatted-and-unformatted-input-output-functions-in-c-with-examples/

⇱ Formatted and Unformatted Input/Output in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Formatted and Unformatted Input/Output in C

Last Updated : 2 Aug, 2025

In C, the input/output functions can be classified into two categories on the basis of how they handle the input/output in terms of formatting or structure:

Formatted I/O Functions

Formatted I/O functions help to display the output to the user in different formats using the format specifiers. These I/O supports all data types like int, float, char, and many more.
The formatted I/O functions in C are discussed below:

printf()

printf() function is used in a C program to display any value like float, integer, character, string, etc on the console screen. It is a pre-defined function that is already declared in the stdio.h(header file). 

Example:


Output
20
This is a string

scanf()

scanf() function is used in the C program for reading or taking any value from the keyboard by the user, these values can be of any data type like integer, float, character, string, and many more. This is a pre-defined function declared in stdio.h(header file). In scanf() function we use &(address-of operator) which is used to store the variable value on the memory location of that variable.

Syntax: 

Example:


Output
Enter a integer number: 
You have entered 0

sprintf()

sprintf stands for "string print". This function is similar to printf() function but this function prints the string into a character array instead of printing it on the console screen.

Syntax:

Example:


Output
2 and 8 are even number

sscanf()

sscanf stands for "string scanf". This function is similar to scanf() function but this function reads data from the string or character array instead of the console screen.

Syntax:

Example: 


Output
c = 2 and d = 8

Unformatted Input/Output Functions

Unformatted I/O functions are used only for character data type or character array/string and cannot be used for any other datatype. These functions are used to read single input from the user at the console and it allows to display the value at the console.

The unformatted I/O functions in C are discussed below:

getch()

getch() function reads a single character from the keyboard by the user but doesn't display that character on the console screen and immediately returned without pressing enter key. This function is declared in conio.h(header file). getch() is also used for hold the screen.

Syntax:  

Example:


Output:

Enter any character: 

getche()

getche() function reads a single character from the keyboard by the user and displays it on the console screen and immediately returns without pressing the enter key. This function is declared in conio.h(header file).

Syntax:


Example:


Output:

Enter any character: g

getchar()

The getchar() function is used to read only a first single character from the keyboard whether multiple characters is typed by the user and this function reads one character at one time until and unless the enter key is pressed. This function is declared in stdio.h(header file)

Syntax: 

Example:


Output:

Enter the character: a
a

putchar()

The putchar() function is used to display a single character at a time by passing that character directly to it or by passing a variable that has already stored a character. This function is declared in stdio.h(header file) 

Syntax:

Example:


Output:

Enter any character: Z
Z

gets()

gets() function reads a group of characters or strings from the keyboard by the user and these characters get stored in a character array. This function allows us to write space-separated texts or strings. This function is declared in stdio.h(header file).

Syntax:


 Example:


Output:

Please enter some texts: geeks for geeks
You have entered: geeks for geeks

puts()

In C programming puts() function is used to display a group of characters or strings which is already stored in a character array. This function is declared in stdio.h(header file).

Syntax:

Example:


Output:

Enter your text: GeeksforGeeks
Your text is: GeeksforGeeks

putch()

putch() function is used to display a single character which is given by the user and that character prints at the current cursor location. This function is declared in conio.h(header file)

Syntax:

Example:


Output:

Enter any character: d
Entered character is: d

Formatted I/O vs Unformatted I/O

Formatted I/O functions                              Unformatted I/O functions                       
These functions allow us to take input or display output in the user's desired format.These functions do not allow to take input or display output in user desired format.
These functions support format specifiers.These functions do not support format specifiers.
These are used for storing data more user friendlyThese functions are not more user-friendly.
Here, we can use all data types.Here, we can use only character and string data types.
printf(), scanf, sprintf() and sscanf() are examples of these functions.getch(), getche(), gets() and puts(), are some examples of these functions.
Comment