From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: fread/fwite return value Date: Wed, 16 Jul 1997 13:13:34 -0400 Organization: Cornell University Lines: 37 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <33CD013E.152B@cornell.edu> References: <199707161302 DOT PAA20053 AT free DOT polbox DOT pl> NNTP-Posting-Host: 128 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk heretic AT polbox DOT com wrote: > So, I wanted to have error checking and I wrote something like > > if ( fread(blah,blah,blah) == -1 ) > { > oh_no_error (); > } > i think it is an error in the docs. AFAIK, fread is supposed to return 0, not EOF, precisely because the return value is size_t, and 0 signifies no bytes read. see the following routine: C:\djgpp\c>fr fr.c #include #include int main(int argc, char *argv[]) { FILE* f; char c; f = fopen(argv[1], "rt"); if (NULL == f) { perror(argv[1]); exit(EXIT_FAILURE); } while( fread(&c, 1, 1, f) ) printf("%c", c); fclose(f); return EXIT_SUCCESS; }