The function getc () in C

The function int getc (FILE * stream) in C Library standard takes the next character (an unsigned char) from the given Stream and increases the position indicator for that Stream.

The function int getc (FILE * stream) in C Library standard takes the next character (an unsigned char) from the given Stream and increases the position indicator for that Stream.

Declare getc () function in C

Below is the declaration for the getc () function in C:

 int getc ( FILE * stream ) 

Parameters

stream - This is the pointer to a FILE object that identifies the Stream on which the operation is performed.

Returns the value

This function returns the character read as an unsigned char that is cast to an int or EOF or an error.

For example

The following program C illustrates the usage of the getc () function in C:

 #include int main () { char c ; printf ( "Nhap ky tu: " ); c = getc ( stdin ); printf ( "Hien thi ky tu vua nhap: " ); putc ( c , stdout ); return ( 0 ); } 

Compiling and running the above C program will result:

The function getc () in C Picture 1The function getc () in C Picture 1

According to Tutorialspoint

Previous lesson: Function fputs () in C

Next lesson: getchar () function in C

5 ★ | 1 Vote