Easy Tutorial
❮ C Function Vprintf C Exercise Example37 ❯

C Library Function - getc()

C Standard Library - <stdio.h>

Description

The C library function int getc(FILE *stream) retrieves the next character (an unsigned character) from the specified stream and advances the position indicator.

Declaration

Here is the declaration for the getc() function.

int getc(FILE *stream)

Parameters

Return Value

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

Example

The following example demonstrates the use of the getc() function.

#include<stdio.h>

int main()
{
   char c;

   printf("Please enter a character: ");
   c = getc(stdin);
   printf("Character entered: ");
   putc(c, stdout);

   return(0);
}

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

Please enter a character: a
Character entered: a

C Standard Library - <stdio.h>

❮ C Function Vprintf C Exercise Example37 ❯