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
Run-Time Check Failure #2 - Stack around the variable 'b1' was corrupted
my problem is when I run my program it tells me that "Run-Time Check Failure #2 - Stack around the variable 'b1' was corrupted.If there is a handler for this exception, the program may be safely continued."
while (!feof(fp))
{
fscanf(fp,…

Erkan Dirikcan
- 11
- 5
0
votes
3 answers
a+ and a mode with fopen()
According to the manual, if you select a/a+ mode in the fopen() function, the file pointer will be placed at the end.
But why do I get 0 using the ftell() and the feof() still returns false? If the file pointer is at the…

ray
- 29
- 1
- 2
0
votes
2 answers
How can I most efficiently read the first n lines of a large text file in php?
So far I'm able to return the entire file, or an empty string. But not the first n lines of a file as expected.
echo head('/path/to/my_file.txt',100); // returns '', or in other versions `1\n1\n...`
function head($filepath, $lines = 1, $adaptive =…

Ryan
- 14,682
- 32
- 106
- 179
0
votes
1 answer
Feof error in C
struct node
{
char item[200];
struct node* next;
};
FILE* unionMethod(char f1name[50], char f2name[50])
{
FILE* f1;
FILE* f2;
f1=fopen(f1name,"r");
f2=fopen(f2name,"r");
char line[200];
struct node *head1=NULL;
struct…

ckaan
- 1
- 1
0
votes
0 answers
C - using feof() with fread
I gotta read some binary files and save them in a dynamic list. When I do it the way I did - see below -, and then print all the products I read, the console shows me 2 products with every field set to 0 (or missing in case of an array). I can't…

Mazza
- 3
- 4
0
votes
1 answer
How to read from unknown file including numbers, letters, and symbols?
How can you read through a file of unknown line lengths (about 1500 lines, so no malloc/alloc and the like is needed because memory is sufficient...luckily, because I don't understand those array/pointer commands yet) including float numbers, signs,…

Lucas
- 125
- 8
0
votes
1 answer
Can't delete the filename and can't rename my temporary file to database-aluno.txt
I'm trying to develop a solution for my algoritms and data structures subject. I have a function that takes a student through a comparison of the number read by a number that exists in my database (corresponds to the number of lines).
Happens right…

Vitor Ferreira
- 163
- 1
- 3
- 11
0
votes
3 answers
Reading from file and exiting loop using feof()
This link tells about why feof() is a bad thing to use as an exit indicator for a loop.
Unsafe ==> having an feof() check in the while, and an fgets() inside the while.
Safe ==> having the fgets()!=NULL check in the while itself.
I'm supposed to…

Somjit
- 2,503
- 5
- 33
- 60
0
votes
1 answer
C ,fscanf(), last line is read twice
Hi I’m doing a test program in C File I/O for my System software (assemblers,loader etc ) course , my problem is the last line is read twice , I remember my teacher told me this is due to some slight syntax or bug I missed ,I forgot what it is ,…

Sainath S.R
- 3,074
- 9
- 41
- 72
0
votes
3 answers
PHP feof() Download - Network Error
I have a bunch of files available for download that I wanted to protect by login and hide the path to prevent hotlinking. I am using a PHP script to do this (Thanks to Mike Zriel for the download script, I have simply added my own database call and…

Barbs
- 1,115
- 2
- 16
- 30
0
votes
1 answer
fscanf loop not working properly
So, i have the following code:
#include
int main() {
FILE* f = fopen("test.txt", "r");
FILE* p = fopen("test2.txt", "w+");
double i;
char j;
while (!feof(f)){
fscanf(f, " %c", &j);
if ((j == '(')||(j == ')'))
fprintf(p, "%c…

Rafael Dias
- 83
- 2
- 9
0
votes
0 answers
counting rows in excel with feof() in c
I am very new to programming so please excuse this stupid question. I want to access CSV files in excel, but I'm not sure how to count the number of rows in the file. Should I use feof() and how?
*FILE *data;
int count;
data = fopen("test.csv",…

Adriaan Sadie
- 1
- 1
0
votes
2 answers
Comparing syntax to feof
Hi guys i am wirting a c programme here and i am trying to print two lines from a text file at a time the problem is that when on the last line if the lines are odd, 3 lines 5 lines. It will print the last line twice.I cant find the comparison of if…

user3809384
- 111
- 1
- 4
- 10
0
votes
0 answers
C++ popen immediate eof after fgets
I'm having a problem running a perl script from within a C++ program using popen.
As soon as I call fgets, feof will return 1
So far, I have the following code.
std::string PerlOutput = "";
std::stringstream CommandToRun;
CommandToRun << "perl " <<…

Mumbles
- 43
- 5
0
votes
1 answer
Matlab load data feof(fid)
i am trying to read data from a text file. The data are just lines with random words.
im trying to skip the empty lines in this file and not load it. I use a loop with fgetl to load the data and the statement feof(fid)==0 to know when the end of…