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
1
vote
2 answers
fgetc() feof() parameter error in php
Today I've got email from my web server admin says that "your service is suspended due to about 60 GB error file. Check the errorlog.txt via FTP." In log file, there are only these two lines repeteadly:
[Tue Apr 04 08:45:52 2017] [error] [client…

WhoCares
- 225
- 1
- 5
- 16
1
vote
1 answer
My loop isn't working(using feof)
FILE *test;
student st;
int i = 0;
test = fopen("example.bin", "rb");
while (feof(test))
{
fread(&st, sizeof(st),1,test);
Class[i] = st;
i++;
}
fclose(test);
So my question is how to read it, put the data in my structure and stop the…

Borislav Nikolaev
- 69
- 5
1
vote
1 answer
Why the last iteration repeats?
My question refers to the while(!feof(arch)) that repeats the last registry two times. Thanks if you take some of your time to answer. I'm in first year learning basics.
The information is on an archive, so the first input shouldn't be 's' because…

Antú Villegas
- 51
- 1
- 10
1
vote
1 answer
Should I use flock when reading a file in PHP?
Ok so I am new to PHP and the example from the book shows that when I write to a file in php i should use flock($fp, LOCK_EX) after opening the file and then flock($fp, LOCK_UN) before closing the file. Like this:
$fp =…

Josh Mayer
- 81
- 4
1
vote
1 answer
How to end scanf by entering only one EOF
I am encoutering this problem. I am using while loop to scan string of numbers and need to end scanning and start proceeding the rest of my program. I just can't figure out, how to flush the stdin or do anything to not press Ctrl+D twice. I just…

Tomas Chalupnik
- 115
- 1
- 14
1
vote
1 answer
feof() detecting end of file one line before actual end
I have a function that should read a file and detect when the file ends.
The function currently reads only the second last line and ends. Can someone please tell me what I'm doing wrong as I can't see it myself:
int readIn(TinCan* inCan, int…

Dawson
- 573
- 6
- 24
1
vote
5 answers
C - Finding end of file BEFORE reading
I have a class that reads "blocks" from a binary file. I use it this way :
while(log.HasNextBlock()) {
block = log.GetNextBlock();
}
My problem is that i need to check inside of the function HasNextBlock() if i am at the end of the file, in…

Virus721
- 8,061
- 12
- 67
- 123
1
vote
1 answer
My loop duplicates the last char... (Language C)(feof)(char by char)
Yo guys,
I'm trying to read a text file:
while(!feof(fp)){
fscanf(fp, "%c", &c);
printf("%c", c);
}
But... the output always duplicate the last char, I dont know why... :/
Any idea?

Frank
- 241
- 1
- 2
- 8
1
vote
4 answers
Why the fscanf is used 2 times with: while( !feof(File))
why when using fscanf to acquire data from a file, is used 2 times, once before the "!feof(fin)" and later, as shown in the code below:
fscanf(fin, "%s", letta);
while(!feof(fin)){
fscanf(fin, "%s", letta);
}
the word read is not the same?

ild0tt0re
- 75
- 7
1
vote
2 answers
How to move file pointer to previous line in php?
Text file in question is named fp.txt and contains 01, 02, 03, 04, 05, ...10 on each line.
01
02
...
10
Code:

DavChana
- 1,944
- 17
- 34
0
votes
4 answers
Paypal IPN Script, issue with feof and fgets
I've been having issues with my Paypal IPN listener script for a couple of days now. For those of you who are unfamiliar with the Paypal IPN system, basically Paypal sends your script with a message about the transaction, which you send back with a…

user1070084
- 383
- 1
- 3
- 11
0
votes
1 answer
I have a trouble in counting amount of "items" in binary file. C
I want to count the amount of "items" in binary file using feof and fseek functions.
I have a binary file with names of people in chars and their salaries in floats.
before each name there is an int that represents the amount of chars in the…

Pentakorr
- 25
- 3
0
votes
2 answers
How safe is using !feof in searching a file?
I read here that feof or more precisely using !feof in searching for a info in a file is a bad habit.
What I understood is that it's bad because it reads information from the FILE pointer before called function or process or something like…

ayoub hmani
- 3
- 2
0
votes
0 answers
EOF not detected right when using strtok()?
So I have a load function that reads in this comma separatedtext data
9780136019701,An Introduction to Organic Chemistry,Timberlake Karen,10,3.54,12-2008
9781506304212,Mathematics for Social Scientists,Kropko…

Saif eldeen Adel
- 318
- 3
- 15
0
votes
0 answers
Rewrite a FEOF while loop to a for loop in c
I need some help to rewrite the feof while loop to a for loop in c.
I have two variables n and m.
Variable n is the size of the array / 1023 in rows and m is columns that are 1023 in size.
#include
#include
#include…