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) returning wrong value
I'm using feof() C function to know whether I am at the end of my file or not, but it seems that it never returns -1 even when I reach the end of the file..
here is what I do :
do {
j+= fscanf(base, "%f %f %f %d", &a, &b, &c, &d);
…

Mehdi Zayene
- 37
- 8
0
votes
2 answers
Duplicate last entry when reading a file using fread
Possible Duplicates:
Why is this C code buggy?
Problem with EOF when determine stream end
I'm trying to read a binary file in 4 byte chunks. However the first implementation (shown below) will duplicate the last entry and only the last…

suyt
- 11
- 1
- 4
0
votes
0 answers
while(!feof(f)){...} explanation
consider
while(!feof(f)){/**do something**/}
I've read that this is wrong, because it executes the loop also one extra time. Can someone explain why? Seems to me that when the end of the file is reached, feof(f) returns true and so the loop does…

waddafunk
- 3
- 1
- 4
0
votes
1 answer
PHP BUG? File-By-Line Transcoding
try this code!
0
votes
1 answer
Why this while condition doesn't catch EOF? and i get segmentation fault
So the problem is, im trying using fgets to read a line from a text and print it out, and it just doesn't work quite well, its read all the file perfectly until the end,but it reads the last line twice and than "shouts" segemnation fault.
void…

Zi Elad
- 1
- 1
0
votes
3 answers
How to skip a comment in c programming with using fopen
I want to ignore/skip the comments in a text file when I use fgets.
The problem is that I only can skip a comment if the first character in a line starts is #. Comments starts with # in my text file. But there are some # in my file.txt that are not…

Stefan Andersson
- 23
- 5
0
votes
0 answers
Why does adding a \n character while appending make it possible to print out the last appended line?
I am trying to write some C code that appends a line of text to a file, and then simply display it line by line. When I open the file in append mode and add a line using fprintf, the line gets added and I can see it when I open the file with a text…

Rahul
- 177
- 3
- 9
0
votes
1 answer
Reclarification of how feof() of php work
I have read the comment about feof() on PHP manual, the answer here on StackOverflow and another answer on StackOverflow.
So I've understood that using feof() does not mean using a 'crystal ball' to magically know whether there are more characters…

Richard
- 7,037
- 2
- 23
- 76
0
votes
2 answers
C--Program not reading end of file correctly
I'm trying to make a basic set of programs where one program asks the user for a set of values which the program writes into a file and where the other program reads the values from the file and prints them to the screen. Here's my code:
The reading…

Sinclair
- 23
- 4
0
votes
0 answers
C - How to use while feof loop to solve empty input file problem?
This is an assignment and my professor only allows us to use feof function to read a file input line by line. Now i have an empty file and I got stuck in an infinite loop.
...
while(!feof(stdin)){
...
char inputLineArray[1000];
…

kluo
- 131
- 1
- 10
0
votes
2 answers
PHP Code Counting Extra Digit
I have typed the following code in PHP to read the text "yusuf123" from the external text file called "sample.txt" and to count and print the total number of digits. The code is surprisingly counting 4 digits instead of 3.
$file =…

Yusuf M
- 27
- 3
- 6
0
votes
1 answer
Can't stop reading Unicode file with !feof()
I don't know why while loop can't stop. It can't compare c with Delim neither stop by reaching eof.
wchar_t* Getline(const wchar_t* Filename, const wchar_t Delim){
FILE* f = _wfopen(Filename, L"r, ccs=UTF-8");
wchar_t* info = NULL;
wchar_t* temp =…
0
votes
0 answers
PHP fread() expects parameter 1 to be a resource, boolean given
I have this errors, the thing is on local server is working just fine, but now when i uploaded the files to the hosting i get these errors.
fread() expects parameter 1 to be resource, boolean given
fseek() expects parameter 1 to be resource,…

Alex
- 50
- 9
0
votes
1 answer
C: strange behavior of feof
I am new to C. I have stumbled upon certain behavior of feof I can't explain. Specifically in the code below I create a file, write one byte of information int it, then close and open it again, read the information (my 1 byte) till EOF is reached,…

zesy
- 481
- 5
- 12
0
votes
1 answer
Why a segmentation fault in feof()?
I have the following enum and struct:
enum Destination { unknown = 0, hosok, parlament, var };
struct Client
{
char name[30];
char email[30];
char phone_num[11];
int client_num;
enum Destination destination;
struct tm…

prophet4955
- 5
- 3