C Library Functions -getchar()

C Standard Library - <stdio.h>

Description

C Library Functionsint getchar(void)Gets a character (an unsigned character) from standard input stdin. This is equivalent togetcWith stdin as a parameter.

Declaration

Below is the declaration of the getchar() function.

int getchar(void)

Parameter

  • NA

Return Value

This function returns the character read as an unsigned char cast to an int, or EOF if end-of-file is reached or a read error occurs.

Example

The following example demonstrates the usage of the getchar() function.

Example

#include <stdio.h>

int main ()
{
   char c;
 
   printf("Please enter a character:");
   c = getchar();
 
   printf("The character you entered:");
   putchar(c);

   return(0);
}

Let us compile and run the above program, which will produce the following result:

请输入字符:a
输入的字符:a

C Standard Library - <stdio.h>

other extensions