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
3 answers

C while loop feof

This is part of a much bigger program to make a filmgenie and for some reason the program crashes as it reaches this while loop and i don't understand what my problem is. #include #include #include #include…
Barry Percy
  • 3
  • 1
  • 1
  • 2
0
votes
2 answers

Segmentation Fault C language reading a simple word

I am writing using CodeBlocks, GCC and using C language. The code I have is as follows: char word[50]; FILE *fn; fn = open("word.txt", "rb"); if(fn == NULL) perror("File not opened"); while(!feof(fn)) { fscanf(fn, "%s", word); } The text file…
Daniel Casserly
  • 3,552
  • 2
  • 29
  • 60
0
votes
1 answer

c debug assertion for calling fgets/fgetc/feof

hey sorry for bothering if this is a really simple issue, but I can't seem to solve this debug assertion failure after so many different trials. I'm merely executing the following code. I have tried using fgets, fgetc or even feof to wrap around the…
Henry Cho
  • 770
  • 2
  • 15
  • 33
0
votes
2 answers

feof or fscanf error

I am doing a program, I use Dev C++. While running my program terminates. On debugging it says 'segmentation fault'. I don't know if it going to infinity loop. I dont know if the problem is with the while(!feof(program)) or the fscanf(...) in the…
george
  • 127
  • 2
  • 5
0
votes
4 answers

C++ Reading file using while loop, start at line "x"

I've been stuck on this issue for a while. What I have here is a loop that will read a text file containing file names. The loop reads these lines one by one, and sets it into memory via the variable sFileName. sFileName is later called upon to load…
Michael
  • 107
  • 1
  • 2
  • 9
-1
votes
1 answer

getting error file format incorrect, reading file in c

if i run 1 data, program execution is success. but in 2 data format file incorrect. where did i go wrong? File .txt 1,Nanggroe Aceh Darussalam,Rumah Sakit,RSU Cut Nyak Dhien,Jl. Tm Bahrum No. 1 Langsa 2,Jawa Barat,Klinik Utama,dr. Sunarhadi,Raya…
xNapz
  • 7
  • 1
-1
votes
2 answers

Why does my feof loop run infinitely, even though the file does end?

So I want to count the lines of the file I have as the argument of the function, but I don't know why does this loop run indefinitely. int count_numbers(FILE *filea) { int i; while (!feof(filea)) { i++; } fclose(filea); …
sawaszef
  • 15
  • 1
-1
votes
1 answer

Why ftell prints -1 as value of file pointer? And why errno prints out "INVALID ARGUMENT"?

I have these 2 functions in a project which loads and saves user's information into a file. Each user is saved in a new line of the file. My problem is that the program crashes when I try to use ftell(f). When I print ftell(f) it prints -1 after…
-1
votes
3 answers

Output struct objects to binary file and input from it back in C

i write managment system in C. i have this structure #define STRING_LENGTH 32 typedef struct { char name[STRING_LENGTH]; } Name; typedef struct{ int id, balance; Name clientName; } Client; i create few test objects, open binary file…
Alex S
  • 66
  • 5
-1
votes
2 answers

PHP: feof miss last word

the problem is simple but complicated at the same time. feof doesn't print my last word. It take from file name city and code (Venice,A908) and should show in OUTPUT: nameCity,codeOfCity. Let me show you an example: City.csv Abano Terme,A001 Abbadia…
-1
votes
3 answers

Getting segmentation fault in fread/fwrite loop, copying file

I am to copy a file from the inputed source to the inputed destination. I am getting a segmentation fault error about 2 seconds after the destination is entered. The output file is created so fopen() is working. I looked online and I see a lot of…
Andrew Ricci
  • 475
  • 5
  • 21
-1
votes
2 answers

PHP: Grouping csv lines when a specific value is equal

Do not think it's difficult , but after a hard day's work I can not get on top of this trivial problem . I have a simple csv file that I have to show through php , grouping the lines from the value of a column . We go specifically : This is my CSV…
fmineo
  • 804
  • 3
  • 11
  • 28
-1
votes
3 answers

php - feof error

The file that I'm trying to read is a pgp-encrypted file. This is part of the process to decrypt it and I'm actually attempting to read the contents into a string so that I can then decrypt it. I'm not sure if that's the core problem here or not,…
TwixxyKit
  • 9,953
  • 9
  • 31
  • 32
-1
votes
1 answer

How to add text to end file text in language c

I have a file in the c language that contains the text i want to add another text to this file without deleting the last text only to add new text at the end of the file
Maximus
  • 11
  • 6
-1
votes
1 answer

problems reading names from a file to insert into a binary tree

Reading from a file of names, I'm trying to put those name into a binary search tree. But for some reason when I read the file, I am starting with a random junk file node: TreeNode* read_from_file(const char* file){ File *fp = fopen(file,"r"); …
user47835
  • 159
  • 2
  • 13
1 2 3
10
11