Standard Library Functions in C

adplus-dvertising
getc() Function
Previous Home Next

Description

The C library function , The getc() function reads a character from the stream pointed to by stream.

Declaration

Following is the declaration for getc() function.

int getc(FILE *stream)

Parameters

stream - Pointer to a FILE object that identifies an input stream. Because some libraries may implement this function as a macro, and this may evaluate the stream expression more than once, this should be an expression without side effects.

Return Value

The getc( ) function returns the next character from the input stream and increments the file position indicator. The character is read as an unsigned char that is converted to an integer.

Example

#include<stdio.h>

int main()
{
   char c;

   printf("Enter character: ");
   c = getc(stdin);
   printf("Character entered: ");
   putc(c, stdout);
   
   return(0);
}

Output

Enter character: b
Character entered: b
Previous Home Next