C library function - getchar()


Advertisements

Description

The C library function int getchar(void) gets a character (an unsigned char) from stdin. This is equivalent to getc with stdin as its argument.

Declaration

Following is the declaration for getchar() function.

int getchar(void)

Parameters

  • NA

Return Value

This function returns the character read as an unsigned char cast to an int or EOF on end of file or error.

Example

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

#include <stdio.h>

int main () {
   char c;
 
   printf("Enter character: ");
   c = getchar();
 
   printf("Character entered: ");
   putchar(c);

   return(0);
}

Let us compile and run the above program that will produce the following result −

Enter character: a
Character entered: a
stdio_h.htm

Useful Video Courses


Video

JCL Online Training

12 Lectures 2 hours

Nishant Malik

Video

COBOL Online Training

12 Lectures 2.5 hours

Nishant Malik

Video

CRO Online Training

48 Lectures 6.5 hours

Asif Hussain

Video

Customer Service Online Training

12 Lectures 2 hours

Richa Maheshwari

Video

Cultivation of Crops

20 Lectures 3.5 hours

Vandana Annavaram

Video

Eclipse Online Training

44 Lectures 1 hours

Amit Diwan

Advertisements