feof in C
File Operations in Tamil

Learn C - C tutorial - Feof in c - C examples - C programs
C - feof() - Definition and Usage
- In C – Programming, the feof function is used to test the end-of-file indicator from the input file stream.

C Syntax
int feof(FILE *stream);
Sample - C Code
#include <stdio.h>
void main()
{
FILE *fp = fopen("sample.txt", "r");
int ch = getc(fp);
while (ch != EOF)
{
putchar(ch); /* display contents of file on screen */
ch = getc(fp);
}
if (feof(fp))
printf("\n End of file reached.");
else
printf("\n Something went wrong.");
fclose(fp);
getch();
}
C Code - Explanation :
- In this statement we create a file pointer “fp”.
- Here in this statement we get the input characters and the characters are assigned to the variable “ch”.
- Here in this printf statement we check whether the file will reach the end of the text or not.
- In this statement we display the string in the output window using putchar function.
- Here in this statement we assign the characters in the variable “ch”.
- In this, “if statement” checks the string gets completed are not using feof function.

Sample Output - Programming Examples

- Here we have shown the text “Welcome To Wikitechy “ from the notepad file “sample.txt” .

- Here in this output, the statement “Welcome To Wikitechy” has been displayed using getc function, when the end of the text reached it displays the text “End of file reached”.