All Questions

409
votes
5answers
163380 views

Why is “while ( !feof (file) )” always wrong?

I've seen people trying to read files like this in a lot of posts lately. Code #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { char * path = argc > 1 ? a...
2
votes
2answers
10582 views

How to use feof(FILE *f)?

I'm having a hard time with a do-while loop, that is supposed to stop when we reach the end of the file. Here's the loop code: do { if (pcompanyRow[0] != '#' && pass == 1) { strt...
26
votes
3answers
11719 views

Why is fread reaching the EOF early?

I am writing a C library that reads a file into memory. It skips the first 54 bytes of the file (header) and then reads the remainder as data. I use fseek to determine the length of the file, and then...
3
votes
3answers
609 views

Why is this C code buggy?

On another question, Jerry Coffin pointed out the following: It's (probably) not really related to your question, but while (!feof(fileptr)){ is pretty much a guaranteed bug. I figured I would s...
7
votes
2answers
19207 views

Reading data from fsockopen using fgets/fread hangs

Here is the code that I am using: if (!($fp = fsockopen('ssl://imap.gmail.com', '993', $errno, $errstr, 15))) echo "Could not connect to host"; $server_response = fread($fp, 256); echo $server_re...
9
votes
2answers
6637 views

How feof() works in C

Does feof() checks for eof for the current position of filepointer or checks for the position next to current filepointer? Thanks for your help !
1
votes
1answers
868 views

How to end scanf by entering only one EOF

I am encoutering this problem. I am using while loop to scan string of numbers and need to end scanning and start proceeding the rest of my program. I just can't figure out, how to flush the stdin or ...
0
votes
1answers
102 views

feof() and fscanf() stop working after scanning byte 1b as a char. Is it because it is 'ESC' in ascii? What can I do?

I'm currently writing a program that processes PPM files (P6 type, not P3) The problem is that some images have the byte 0x1b which, according to the ascii table is known as 'ESC' The following is pr...
3
votes
2answers
18897 views

how use EOF stdin in C

I need to input coordinates into an array until EOF is encountered, but something is wrong in my code. I used ctrl+Z, ctrl+D int main() { int x[1000],y[1000]; int n=0,nr=0,a,b,i; printf(...
0
votes
4answers
4050 views

Paypal IPN Script, issue with feof and fgets

I've been having issues with my Paypal IPN listener script for a couple of days now. For those of you who are unfamiliar with the Paypal IPN system, basically Paypal sends your script with a message a...

Previous Next