C feof() function
C library function - feof()
The feof() function indicates whether the end-of-file flag is set for the given stream.
Syntax:
int feof(FILE *stream)
feof() Parameters:
Name | Description | Required /Optional |
---|---|---|
stream | Identifies an address for a file descriptor, which is an area of memory associated with an input or output stream. | Required |
Return value from feof()
- The feof() function shall return non-zero if and only if the end-of-file indicator is set for stream.
Example: feof() function
This example read a text file until it reads an end-of-file character.
#include <stdio.h>
int main () {
FILE *fp;
int c;
fp = fopen("file.txt","r");
if(fp == NULL) {
perror("Error in opening file");
return(-1);
}
while(1) {
c = fgetc(fp);
if( feof(fp) ) {
break ;
}
printf("%c", c);
}
fclose(fp);
return(0);
}
Output:
c Programming1 c Programming2 c Programming3
C Programming Code Editor:
Previous C Programming: C clearerr()
Next C Programming: C ferror()
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join