Showing posts with label feof function in c. Show all posts
Showing posts with label feof function in c. Show all posts

Friday, December 18, 2020

, ,

Write a program for feof function in c

 feof function in c programming is used for file handling.

 feof c use to find the end of an file.

Syntax for feof c program :- 

int feof(FILE *fp)

Example program for feof function in c

# include <stdio.h>
int main( )
{
   FILE *fp ;
   char c ;
   printf( "Opening the file test.c in read mode" ) ;
   fp = fopen ( "test.c", "r" ) ; // opening an existing file
   if ( fp == NULL )
   {
     printf ( "Could not open file test.c" ) ;
     return 1;
   }
   printf( "Reading the file test.c" ) ;
   while ( 1 )
   {
     c = fgetc ( fp ) ; // reading the file
     if( feof(fp) )
     break ;
     printf ( "%c", c ) ;
   }
   printf("Closing the file test.c as end of file is reached.");
   fclose ( fp ) ; // Closing the file
   return 0;
}

This file handling program use to read a open file and feof c function used to find the end of the file.

feof c
program output for feof c