VOOZH about

URL: https://www.geeksforgeeks.org/c/getchar-function-in-c/

⇱ getchar Function in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

getchar Function in C

Last Updated : 30 May, 2026

The getchar() function in C is a standard library function used to read a single character from the standard input device (keyboard). It is commonly used for simple character-based input operations.

  • Reads one character at a time from the standard input stream (stdin).
  • Defined in the <stdio.h> header file.

Output
Enter a character: You entered: �

Syntax

int getchar(void);

getchar() function does not take any parameters.

Return Value

  • Returns the entered character as an integer (int) representing its ASCII value.
  • Returns EOF (End Of File) if the end of the input stream is reached or an input error occurs.

Examples of C getchar Function

The following C programs demonstrate the use of getchar() function

Example 1: Read a single character using getchar() function.


Input

f

Output

The entered character is : f

Example 2: Program to implement putchar to print the character entered by the user:


Input

Enter any random character between a-z: k

Output

The entered character is : k

Example 3: Reading multiple characters using getchar()


Input

geeksforgeeks

Output

geeksforgeeks

Example 4: Read sentences using getchar() function and do-while loop.


Input

Enter the characters
Welcome to GeeksforGeeks

Output

Entered characters are Welcome to GeeksforGeeks
Comment