File Operations in Tamil


 feof-in-c

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.
feof-in-c

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 :

  1. In this statement we create a file pointer “fp”.
  2. Here in this statement we get the input characters and the characters are assigned to the variable “ch”.
  3. Here in this printf statement we check whether the file will reach the end of the text or not.
  4. In this statement we display the string in the output window using putchar function.
  5. Here in this statement we assign the characters in the variable “ch”.
  6. In this, “if statement” checks the string gets completed are not using feof function.

Sample Output - Programming Examples

  1. Here we have shown the text “Welcome To Wikitechy “ from the notepad file “sample.txt” .
  1. 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”.

View More Quick Examples


Related Searches to C feof