Ads (728x90)

getchar() and putchar()



Syntax Getchar()

variable = getchar("characters");

example:

C = getchar("C");

C is the variable.
getchar() is the input function.
inner C is the character which was used in program

Syntax Putchar()

variable = getchar("characters");

example:

C = putchar("C");

C is the variable.
putchar() is the input function.
inner C is the character which was print on print screen.

Example Program

#include<stdio.h>
#include<conio.h>
void main ( )
{
char c ;
clrscr ( );
c = getchar();
putchar(c);
printf ( "The input character is %c" , c );
getch ( );
}

Explanation:


  • Header file as stdio.h and conio.h
  • Main function that was heart of the c program
  • Variable declaration, That "char c;" statement used for variable declaration. char keyword indicate the variable is based on character storing. 
  • Clrscr() function was used to clear previous output on output screen.
  • C variable was get the value from getchar() function. getchar() function is predefined. So i get single character from users. More than 1 character its cannot get. 
  • Putchar() functions also predefined function it's display values which variable pass. 
  • printf() also used to display statement of strings.
  • getch() is the functions used to hold the output screen to use.
  • end of file 

Its simple way of getting values from users by getchar() and putchar().

Post a Comment