Questions tagged [feof]

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.

157 questions
0
votes
0 answers

What is While Feof alternative for big file downloads?

I use this while loop to fetch the file;
BroserBros
  • 17
  • 6
0
votes
1 answer

Queues Using Linked List in C only take last node as a whole infinite queue

I am working on a data structure project. I am asked to take information from a file called "ToServe.txt". The data in the file is in the form: TicketNumberSpaceStudentIDSpaceStudentName TicketNumberSpaceStudentIDSpaceStudentName However,…
0
votes
0 answers

Why does my fscanf() go into an endless loop?

#define F_PWD_FSCANF "%05d%30[^\n]%15s%25s%30s\n" #define F_PWD_FPRINTF "%05d%-30s%-15s%-25s%-30s\n" int main(){ FILE *fp=fopen(FILENAME(F_PWD),"a+"); if (!fp) { …
Anil
  • 15
  • 4
0
votes
1 answer

How to add certain prefixes to lines from a file

So I have a text file (called So.txt) that has in it: Will Happy 12.50 2012 Kanye Wolves 15.99 2016 I'm writing a program that reads from it and adds a certain prefix to each read line. Basically I would like the output to look like this: Name of…
0
votes
2 answers

Check EOF after fread in a loop

I figured out why the following loop was giving me bad input, re Why is “while ( !feof (file) )” always wrong? do { if (fread(buf, 1, siz, stdin) != siz) { if (feof(stdin)) fputs("bad input\n", stderr); else /*…
beardeadclown
  • 327
  • 2
  • 14
0
votes
0 answers

feof causing Segmentation fault (core dumped) error?

I'm trying to make a function that gets a dynamically allocated string from a file, ignoring leading whitespace and going until it reached whitespace again, but I keep get a "Segmentation fault (core dumped)" error. I tried using valgrind to find…
Jay P.
  • 1
  • 1
0
votes
1 answer

loop once more in C

I write c program that reads a file (argv1) line by line my text file is this : This is my code #include #include void read_fp(FILE *fp){ char buffer[50]; fgets(buffer, sizeof(buffer), fp); printf("%s",…
skk
  • 67
  • 4
0
votes
0 answers

Why does feof return a different result when it is used with fseek and fread?

While debugging a function I am implementing, I noticed a different return result from feof when it is used with fseek or fread, would you explain to me why feof is unable to test the end of file when fseek get involved? $file = fopen('data.txt',…
H Aßdøµ
  • 2,925
  • 4
  • 26
  • 37
0
votes
2 answers

Using feof to read whole file and print result give me double end

I have, I'm trying to read a binary file until end and print the result, I'm using and while with "feof" to read until end of file and printing each result, but I have a problem it is giving me double end result. I'm still learning C, so I don't…
Vinanrra
  • 63
  • 7
0
votes
1 answer

Why doesn't this code need clearerr for feof?

Every stream has an "end-of-file (EOF) flag". The flag is only cleared if you call the clearerr function on the stream. feof(p) function returns the current state of this EOF…
Test Raw
  • 3
  • 2
0
votes
0 answers

How to input eof(Ctrl+z) while letting the scanf have a space before the specifier to avoid getting previous \n error?

( I hit enter) #include #include int main(){ int target,result; while(1){ printf("Please input your target: "); scanf(" %d",&target); if(feof(stdin)){ break; } …
0
votes
2 answers

Is this an acceptable way to determine EOF while reading a file in PHP?

I am fairly new to PHP and just trying to convert something I did in C. The idiom for reading from a file in C that I was taught was: while ((c = getchar()) != EOF) { doSomethingWith(c); } I've done some reading and it would seem that the…
Steve
  • 1,439
  • 2
  • 14
  • 27
0
votes
2 answers

when copying strings from one text file to another, the last line in the original file is not copied

edit: change the code to my real code, because i was told that the shortened one i posted couldn't be compiled. hope it helps in finding the problem i have a struct as below: struct patient { char name[30], ID[8]; int age, phoneNo; }; and…
cloud
  • 105
  • 9
0
votes
0 answers

How do i print the char value from file c program?

#include #include #include #define BUFFER_SIZE 128 const char *FILE_GAME_DATA_PATH = "./game.txt"; struct game_tag { char gname[20]; struct game_tag *next; } * head; //struct game_tag g; typedef struct…
0
votes
1 answer

Exiting out of file with feof function

I am trying to make a photo extraction program stop when it detects it is at the end of the file to be extracted. I did this by placing an if condition: if (feof(file)) { return 2; } After a fread function: fread(array, 1, 512, file); So that…
ckwan
  • 7
  • 1