C Library Functions -getc()
C Standard Library - <stdio.h>
Description
C Library Functionsint getc(FILE *stream)Gets the next character (an unsigned char) from the specified stream and advances the position indicator.
Declaration
The following is the declaration of the getc() function.
int getc(FILE *stream)
Parameter
- streamThis is a pointer to a FILE object that identifies the stream on which the operation is to be performed.
Return Value
The function returns the character read as an unsigned char cast to an int, or EOF if the end of file is reached or a read error occurs.
Example
The following example demonstrates the usage of the getc() function.
#include<stdio.h>
int main()
{
char c;
printf("请输入字符:");
c = getc(stdin);
printf("输入的字符:");
putc(c, stdout);
return(0);
}
Let us compile and run the above program, which will produce the following result:
请输入字符:a 输入的字符:aother extensions