Mail Archives: djgpp/1997/07/17/04:49:07
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 <stdio.h>
#include <stdlib.h>
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;
}
- Raw text -