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
2
votes
2 answers

How does C handle EOF?

#include int main() { FILE* f=fopen("book2.txt","r"); char a[200]; while(!feof(f)) { fscanf(f,"%s",a); printf("%s ",a); printf("%d\n",ftell(f)); } fclose(f); return 0; } I have the…
joy
  • 721
  • 2
  • 11
  • 18
1
vote
1 answer

How to read from stdin with fgets()?

My professor write a C code about fgets,feof with using stdin. But I don't understand how it works. fgets(list, 100, stdin); while (!feof(stdin)) { printf("feof!"); fgets(list, 100, stdin); } when i write a 'hello', function while is…
Oliver
  • 11
  • 1
1
vote
2 answers

While loop in C Language with feof condition and fgets elaborate twice for no reason?

I have a text file with a lots of records (about 20k lines) that is written like…
sirducas
  • 45
  • 6
1
vote
1 answer

How do I read the last line of a text file in a C program?

I'm trying to study the C language and basically what I want to do is read a file and put it into a struct I created, and then later I'll be doing other things with the struct, but I want to get through the first part first. Let's say that I have a…
Emil Lang
  • 35
  • 6
1
vote
1 answer

make FEOF return true sooner to avoid explode() "Undefined offset" error (PHP)

I have this simple program that print the content of a file "; $ligne=fgets($fp); $row=explode("|",$ligne); …
Marwane
  • 333
  • 3
  • 13
1
vote
0 answers

How to get rid of the "Uncaught TypeError: feof(): supplied resource is not a valid stream resource" logged error?

For years now, I've been trying to solve this insanely annoying issue. Seemingly at random, my fsockopen-using code fails and PHP-logs the error: PHP Fatal error: Uncaught TypeError: feof(): supplied resource is not a valid stream resource For…
1
vote
2 answers

How to search in particular lines of txt file with php

I store data from an article in a .txt file. A txt file looks like this: id_20201010120010 // id of article Sport // category of article data/uploads/image-1602324010_resized.jpg //…
john
  • 1,263
  • 5
  • 18
1
vote
1 answer

Size of array out of range

I'm trying to write code that reads couple of numbers from FILE in the form of x y and stores them in two arrays, and i want the function to returns the number of couples, i tried with a FILE that contains 5 couples, but it seems that FILE *ptr goes…
user14356872
1
vote
1 answer

Problem with reading file...while (!feof(file)) leads to infinite loop!

void OpenFile() { FILE *fp; char buffer[1024]; int number; fp=fopen("godess.txt","r"); if(fp==NULL){ printf("Error opening file!\n"); exit(0); } else { while (!feof(fp)) { …
xcubis
  • 11
  • 2
1
vote
1 answer

read text from file via .php and store parts in variable

Problem is reading text from file and prepare and save specific text to variables for insert into database. Something like here: https://www.wdb24.com/php-read-text-file-and-insert-into-mysql-database/ Measurment/Import data looks like: …
ejovrh2
  • 59
  • 9
1
vote
2 answers

Attempting to read in a file and storing the first input in an array val and the second input in an array wt (weight)

I need to read in a file called "data.txt" and store the first input as a value and the second corresponding input as a weight. I'm having issues reading them in and storing the values. data.txt (example) 3 25 2 20 1 15 4 40 5 50 This is what I´ve…
1
vote
1 answer

How do you differentiate between the end of file and an error using fscanf() in C?

According to manual, int fscanf(FILE *stream, const char *format, ...) returns the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure. How shall I…
tomashauser
  • 561
  • 3
  • 16
1
vote
4 answers

C segmentation fault errors with feof() and fgetc()

Can anyone help me solve my dilemma? When I compile my program I get no errors or warnings. When I go to actually run the executable, though, I get a segmentation error. If I'm to understand correctly, this happens because a pointer is in short…
learning
  • 11
  • 1
  • 3
1
vote
1 answer

feof becomes true prematurely

I am trying to send a file over a socket by reading one character at a time until the buffer (an array of chars) is full, sending it, then repeating until the end of the file. But for some reason feof becomes true before the file ends (I believe it…
Dasonic
  • 375
  • 1
  • 5
  • 13
1
vote
1 answer

Check if the input stream is empty in C

I'm learning C language, I'm having trouble with my program. So, I have this program called TEST this program should allow me to read the argument either with argv[] or by using the input stream $ TEST < argsTest.json. argsTest.json : { "a" = 2, "b"…
Haskell-newb
  • 149
  • 1
  • 10
1 2
3
10 11