Table of Contents
C Data input/output functions
Data input and output functions Character I/O format
getch()
getche()
getc()
getchar()
gets()
putchar()
putc()
puts().
getch()
getch() is available in “conio.h” header in C programming. This header is mostly used by MS-DOS compilers to provide console input/output. “conio.h” is not part of the C standard library or ISO C, also it is not defined by POSIX. getch() is a nonstandard function.
getch() reads a single character from a keyboard and returns it immediately. Buffer is not used by getch() hence it returns the character even before the “enter”.
It will hold the output screen console until any key pressed.
The Entered character will not be displayed on the console screen.
There is no buffer to store an input character.
It can be used to accept hidden inputs like password, PIN etc.
Syntax :
int getch(void)
It accepts nothing in parameters.
It will return the ASCII value of the key which has been pressed.
#include<stdio.h>
#include<conio.h>
int main()
{
printf("%c", getch());
return 0;
}
Input : v
Output: Output screen will get terminated immediately. If you use DOS shell in C then it will display a signal 'v'
getche()
Like getch(), getche() is also a nonstandard function. This is also available in conio.h header.
It also accepts a character from the keyboard but unlike getch() it will display the character on screen. There is no buffer in getche().
Syntax :
int getche(void);
#include <stdio.h>
#include <conio.h>
int main()
{
printf("%c", getche());
return 0;
}
Input : v
Output: Output screen will get terminated immediately. If you use DOS shell in C then it will display a signal 'v'
getc()
It reads a single character from an input stream and returns the ASCII value of the key which has been pressed. It returns EOF on failure or when it encounters an error.
Once the character is read from the stream it will move forward the position indicator in the stream. It can read from any input stream like file or console.
Syntax:
Int getc(FILE *stream)
stream is the pointer to a FILE object.
#include <stdio.h>
int main()
{
printf("%c", getc(stdin));
return(0);
}
Input : v
Output: v
getchar()
getchar() reads a single character from standard input (stdin); it is equal to getc(stdin).
It returns the character ASCII value of the key which has been pressed or EOF on failure or when it encounters an error.
Syntax :
int getchar(void);
#include <stdio.h>
int main()
{
printf("%c", getchar());
return(0);
}
Input : v
Output: v
gets()
It reads a string from standard input (stdin) and stores it in a character array (string variable). It has a pointer as parameter which points to the character array in which the data string will be stored.
It will return str once it completes reading without any error. It will stop when it encounters the end of line or next line character.
Syntax :
char *gets(char *str);
str will point to a char array.
#include <stdio.h>
int main () {
char name[20];
printf("Enter a your name : ");
gets(name);
printf("Name : %s", name);
return(0);
}
Output: Enter your name : ITVoyagers
Name : ITVoyagers
putchar()
As the name suggests it is used to write a single character on standard output (stdout). The character which is to be displayed is passed as a parameter in putchar().
Syntax :
int putchar(int char);
It will return an unsigned character on stdout. It will return EOF when error occurs.
#include <stdio.h>
int main () {
char al;
for(al = 'a' ; al <= 'z' ; al++) {
putchar(al);
}
return(0);
}
Output: abcdefghijklmnopqrstuvwxyz
putc()
It is used to write a single character in file, it will write a character in stream and it will move forward the indicator’s position.
It is a C library function.
It returns the character written as an unsigned char cast to an int or EOF when it encounters an error.
Syntax :
int putc( int char, FILE * stream );
char : it is a character which is to be written.
stream : it is a file pointer which states in which file character is to be written.
#include<stdio.h>
int main () {
FILE *itvfile;
int ch;
printf("Enter your name : ");
fp = fopen("itvfile.txt", "w");
for( ch = 0 ; ch <= 10; ch++ ) {
putc(ch, itvfile);
}
fclose(itvfile);
return(0);
}
Output: Enter your name : ITVoyagers
“ITVoyagers” will get store in itvfile.txt
puts()
It is used to display/write a string to a standard output (stdout). It does not include NULL characters.
It will append new line character after each and every output.
Non-negative value is returned on success and on error, it returns EOF.
Syntax :
int puts(const char *str)
#include <stdio.h>
#include <string.h>
int main () {
char str[] = "Welcome to world of IT";
puts("ITVoyagers");
puts(str);
return(0);
}
Output: ITVoyagers
Welcome to world of IT
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
PRACTICALS IN C PROGRAM

Im thankful for the post. Much thanks again. Awesome. Aurlie Griz Demetra
Hi there mates, its wonderful post about educationand entirely defined, keep it up all the time. Josie Henri Carlick