Computer Science, asked by dandumanojkumarreddy, 2 months ago

When getc() returns EOF?​

Answers

Answered by vishakasaxenasl
0

Answer:

EOF means End of the File. getc() returns EOF when it is failed to do some operations or it encounters the end of the file.

Explanation:

getc() Function

getc() is an standard function of C language that is a part of <stdio.h> header file.

It is used to read the character from the input stream. Sometimes, getc() returns EOF which means either it reaches the end of the file or it fails to perform the required operation.

EOF is defined as that condition where no more data can be fetched from the given source.

getc() is also used in file handling. It can read the characters from the file

For example:

#include<stdio.h>

int main()

{

 FILE *fp = fopen("exmaple.txt", "r");

 int ch = getc(fp);

 while (ch != EOF)

 {

   //To display the contents of the file on the screen

   putchar(ch);

   ch = getc(fp);

 }

return 0;

}

#SPJ3

 

Similar questions