The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Unformatted Functions

Unformatted input and output functions are only work with character data type. Unformatted input and output functions do not require any format specifiers. Because they only work with character data type.

Character IO Functions

getchar() Function

The getchar() function reads character type data form the input. The getchar() function reads one character at a time till the user presses the enter key.

getchar() C Program

getchar.c
#include <stdio.h> //header file section
#include <conio.h>
int main()
{
char c;
printf("Enter a character : ");
c = getchar();
printf("\nEntered character : %c ", c);
return 0;
}
  • Enter a character : y
  • Entered character : y

Note:

Here, getchar() reads the input from the user and display back to the user.

getch() Function

The getch() function reads the alphanumeric character input from the user. But, that the entered character will not be displayed.

getch() C Program

getch.c
#include <stdio.h> //header file section
#include <conio.h>
int main()
{
printf("\nHello, press any alphanumeric character to exit ");
getch();
return 0;
}
  • Hello, press any alphanumeric character to exit

Note:

The above program will run until you press one of many alphanumeric characters. The key pressed by you will not be displayed.

getche() Function

getche() function reads the alphanumeric character from the user input. Here, character you entered will be echoed to the user until he/she presses any key.

getche() C Program

getche.c
#include <stdio.h> //header file section
#include <conio.h>
int main()
{
printf("\nHello, press any alphanumeric character or symbol to exit \n ");
getche();
return 0;
}
  • Hello, press any alphanumeric character or symbol to exit
  • k

Note:

The above program will run until you press one of many alphanumeric characters. The key pressed by you will be echoed.

putchar() Function

putchar() function prints only one character at a time.

putchar() C Program

putchar.c
#include <stdio.h> //header file section
#include <conio.h>
int main()
{
char c = 'K';
putchar(c);
return 0;
}
  • K

Note:

Here, variable c is assigned to a character 'K'. The variable c is displayed by the putchar(). Use Single quotation mark ' ' for a character.

putch() Function

The putch() function prints any alphanumeric character.

putch() C Program

putch.c
#include <stdio.h> //header file section
#include <conio.h>
int main()
{
char c;
printf("Press any key to continue\n ");
c = getch();
printf("input : ");
putch(c);
return 0;
}
  • Press any key to continue
  • input : d

Note:

The getch() function will not echo a character. The putch() function displays the input you pressed.

String IO Functions

gets() Function

The gets() function can read a full string even blank spaces presents in a string. But, the scanf() function leave a string after blank space space is detected. The gets() function is used to get any string from the user.

gets() C Program

gets.c
#include <stdio.h> //header file section
#include <conio.h>
int main()
{
char c[25];
printf("Enter a string : ");
gets(c);
printf("\n%s is awesome ",c);
return 0;
}
  • Enter a string : Randy Orton
  • Randy Orton is awesome

Note:

The gets() function reads a string from through keyboard and stores it in character array c[25]. The printf() function displays a string on the console.

puts() Function

The puts() function prints the charater array or string on the console. The puts() function is similar to printf() function, but we cannot print other than characters using puts() function.

puts() C Program

puts.c
#include <stdio.h> //header file section
#include <conio.h>
int main()
{
char c[25];
printf("Enter your Name : ");
gets(c);
puts(c);
return 0;
}
  • Enter your Name: john
  • john

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report