The `feof` function is available as part of the C Standard Library and checks whether the end of a stream has been reached. Usually, when it is used, the code using it is wrong.
Questions tagged [feof]
157 questions
0
votes
0 answers
feof(file) does not terminate loop in cLion for macOS
Why does this code result in infinite loop on cLion, while on opening the project on Xcode it works normally and terminates on finding on EOF?
while (!feof(file)) {
fscanf(file, "%d", &number);
printf("%d\t",number);
}

Fady Nabil Yacoub
- 162
- 6
0
votes
4 answers
How do I read the contents of a file in C and store it into an array using fgets()?
So I need to create a word search program that will read a data file containing letters and then the words that need to be found at the end
for example:
f a q e g g e e e f
o e q e r t e w j o
t e e w q e r t y u
government
free
and the list of…

McLovinIt
- 45
- 1
- 6
0
votes
0 answers
C stdin and CTRL+C copies previous line
I am trying to read from stdin with fgets which is an alternate way to read apart from a file. The thought is that I should be able to write as many lines as I want and stop reading from stdin with CTRL+C is entered or any other bash terminating…

Cows42
- 307
- 3
- 12
0
votes
1 answer
Reading ints in a file of mixed types, "feof" not working
I'm getting bugs in my program (that is supposed to find all ints in and file of chars and ints) where "feof" doesn't work (while loop never ends) or no integers are read/found unless the entire file is full of ints.
My code...
#include
…
user7520896
0
votes
1 answer
How does file pointer shifts when fread() function is called?
//Libraries are called accordingly
struct std
{
int a;
char b;
}// a structure with 2 objects
void main()
{
std h[5]; // structure array with 5 elements
int rec_size; // Size of single record to be accessed from the file…

adits2
- 11
- 2
0
votes
4 answers
Merge two files in C
I want to merge two files in C, and stop in the end.
I have a program but it keeps spelling out words even after my file is ended. For example:
File 1:
a
b
c
File 2:
1
2
3
4
5
And the result I get is:
a
1
b
2
c
3
c
4
c
5
And I…

Karim
- 1
0
votes
1 answer
using while(!feof) with terminating condition ,still it is going in infinite loop in c
I am coding a program for a library management system as my project in c. I used a while loop along with !feof condition to check the file for book. Since I read that we should not use it, and if we must, we should do it with some break statement…

vc59
- 3
- 2
0
votes
1 answer
Comparing two files char by char - end of file error in C
I have a specific problem. I have to read Strings from two files and compare them char by char, and tell in which row is the difference and for how many chars they differ. I have made pointer and all stuff, but the problem is when it comes to the…

Buzz Black
- 53
- 1
- 6
0
votes
0 answers
feof gives extra loop in c
The reason why I have written this post is because no other post on SO solves my problem. I've read all the posts on this subject and tried/tested the suggestions, but they dont work in the context of the code I posted - hence the post in the first…

Ke.
- 2,484
- 8
- 40
- 78
0
votes
1 answer
Reading text file from stdin stops at last line
I wrote a short program to test reading text files from stdin:
int main(){
char c;
while(!feof(stdin)){
c = getchar(); //on last iteration, this returns '\n'
if(!isspace(c)) //so this is false
…

corporateWhore
- 617
- 2
- 12
- 23
0
votes
2 answers
Strings won't concatenate correctly in PHP
I have a loop running in a PHP script that's part of a .inc.php (it's a header that reads from a .txt file so that it can add to it's navbar from information solely from the .txt). For example, in the .txt could be:
about
contact
support
It reads…

Rocky
- 47
- 1
- 11
0
votes
1 answer
Tell AJAX that the request was completed without canceling file upload
I am sorry if the title was misleading, there is no easy way to abridge my issue in a title. I am currently experimenting with AJAX file uploads; I had done standard file uploads before but now I am trying to make my application's interface a bit…

CristianHG
- 442
- 5
- 16
0
votes
1 answer
File in C is identifying unecessary line
My program should read some segments to id a plane. 3 segments per line.
The input archive is:
3 4 25 -4 -30 2 6 7 9 10 3 4
3 4 4 -4 -3 2 6 7 9 10 5 6
and it is read as coordinates:
(3, 4) (25, -4) (-30, 2) (6,7) (9,10) (3,4)
A Segment would be a…

Laura Martins
- 583
- 2
- 6
- 15
0
votes
1 answer
Function `feof` Always Returns 1
I'm trying to read in a binary file of size 114,808 bytes. I allocate memory for the file, and then try to read in the file using fopen and fread. The first time fread is called, it always reads in 274 bytes, and the subsequent call to feof always…

Jim Fell
- 13,750
- 36
- 127
- 202
0
votes
1 answer
losing data when reading a file with fscanf
using a part of code like this:
fscanf(f1, "%d", &n);
while(!feof(f1)){
...
fscanf(f1, "%d", &n);}
it misses the last line of the file (meeting EOF). How should I solve?
the only solution i found is:
if (fscanf(f1, "%d",…

StackUser
- 1,530
- 3
- 13
- 17