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 libraries. It reads only a single input from the user and displays the value on the console output screen.
Disadvantages of Unformatted Input and Output Functions
- This function doesn't allow giving input and output in the desired manner.
- In this function, there are no format specifiers in the syntax.
- In this function, the data is not stored in a user-friendly manner.
- Most of these functions, are used to store the character data or string data.
Types of Unformatted Input and Output Function in C
- getch()
- getche()
- getchar()
- putchar()
- gets()
- puts()
- putch()
1. getch():
getch() function is a built-in function declared in conio.h header file. It reads a single character from the keyboard. The input character won't be displayed on the console Output screen. getch() function immediately returns the input character without pressing the enter key.
Syntax:
getch() or variable name= getch();
In this function we won't pass any parameters, and it returns a single character, but it won't be displayed on the console output screen.
Example program on getch() function:
// C program to implement getch() function in C
#include <conio.h>
#include <stdio.h>
int main()
{
printf("Enter any character: ");
getch(); // A character is entered, but it won't be displayed on the screen
return 0;
}
Output:
Enter any character:
2. getche():
getche() function is a built-in function declared in conio.h header file. It reads a single character from the keyboard. The input character will be displayed on the console Output screen. getch() function immediately returns the input character without pressing the enter key.
Syntax:
getche() or variable name= getche();
In this function, we won't pass any parameters, and it returns a single character, but it will be displayed on the console output screen.
Example program on getche() function:
// C program to implement getche() function in C
#include <conio.h>
#include <stdio.h>
int main()
{
printf("Enter any character: ");
getche(); // A character is entered but it will be displayed on the screen immediately
return 0;
}
Output:
Enter any character: H
3. getchar():
getchar() function is a built-in function declared in stdio.h header file. It reads a single character from the keyboard if the user enters multiple characters or a single character.
Syntax:
Variable name= getchar();
In this function, we won't pass any parameters, and it reads a single character, but it can be displayed on the console output screen using output functions.
Example program on getchar() function:
// C program show the functionality of getchar() function
#include <stdio.h>
int main()
{
charch; // declaring a character variable
printf("Enter the character: ");
ch = getchar(); // reading the character from the keyboard
printf(" \nThe entered character is: %c", ch); // printing the entered character
return 0;
}
Output:

In the output, we gave the input as "Hello", but in the output, it displayed only H. By this, we can say only the first character is considered in the getchar() function.
4. putchar():
putchar() is a built-in function present stdio.h header file. It displays a single character from the keyboard if the user enters multiple characters or a single character.
We can pass the character into the function or by passing a variable which has stored a character.putchar() prints a single character.
Syntax:
putchar(variable_name);
It takes a single character or a variable as parameter. And return a character on the console output screen.
Example program on putchar() function:
// program to implement putchar function
#include <stdio.h>
int main()
{
charch; // declaring the character
printf("Enter any character: ");
// Reads a character
scanf("%c",&ch);
// Displays that character using putchar function
printf(" \nThe entered character is: ");
putchar(ch); // method 1
printf("\n second method\n The passed character is: ");
putchar('A'); // Method 2
return 0;
}
Output:

5. gets():
gets() is a built-in function present stdio.h header file. By using gets() function, we can read the collection of characters or a string. We should have to declare a character array to store the string. This function allows spaces in the string.
Syntax:
charstr[ size ]; //declaration of character array
gets(str);
This function takes a character or a string as a parameter. And it won’t have any return data type.
Example program:
// program to implement the gets() function in C
#include <stdio.h>
// Driver code
int main()
{
charstr[100]; // declaration of character array str of size 100
printf("Please enter a string: ");
gets(str); // reading the string using gets() function
printf(" \nThe Entered string is: %s",str); // printing the string
return 0;
}
Output:

6. puts():
puts() is a built-in function present stdio.h header file. By using puts() function, we can print the collection of characters or a string. We should have to declare a character array to store the string. This function also prints spaces between the characters.
Syntax:
puts( character array);
This function takes a character array or a string as a parameter. And returns a string or a character array on the console output screen.
Example:
// program to implement the gets() function in C
#include <stdio.h>
// Driver code
int main()
{
charstr[100]; // declaration of character array str of size 100
printf("Please enter a string: ");
gets(str); // reading the string using gets() function
printf(" \nThe Entered string is: %s",str); // printing the string using printf()
printf(" \nThe Entered string is: ");
puts(str); // printing the string using puts function
return 0;
}
Output:

7. putch():
putch() function is a built-in function in C present in conio.h header file. It is used to display a single character on the console output screen.
Syntax:
putch( variable name );
This function takes a single character or a variable as a parameter. And it returns a single character on the console output screen.
Example program:
// program to implement the putch() function in C
#include <stdio.h>
// Driver code
int main()
{
charch;
printf("Enter any character:\n ");
ch = getch(); // reading the character using getch() function
printf("\nTheEntered character is: ");
// Displays that character on the console output screen
putch(ch); // using putch() function
return 0;
}
Output:
Enter any character:
The Entered character is: H
Conclusion
In this article, we learned about the unformatted input and output functions, the definition and disadvantages of this function and discussed examples of each and every unformatted i/o function.