putchar(), getchar() function in C

Introduction

getchar() and putchar() function is a file handling function in C programming language which is used to write a character on standard output/screen. getchar() function is used to get/read a character from keyboard input.

The getchar() function reads a character from the terminal and returns it as an integer. This function reads only single character at a time.

The putchar() function displays the character passed to it on the screen and returns the same character. This function too displays only a single character at a time. In case you want to display more than one characters, use putchar() method in a loop.

Example 1:



Output:

 Enter some character. Enter $ to exit…
 A
 Entered character is: A
 B
 Entered character is: B
 $
 Entered character is: $


Example 2:



Output:

 $./a.out
 Enter a value : this is test
 You entered: this is test