In article
<e9**********************************@b32g2000hsa. googlegroups.com>,
Spiros Bousbouras <sp****@gmail.comwrote on Monday 19 Nov 2007 8:52
pm:
/* ... */
f = fopen("some-file" , "r") ;
if ( f == NULL ) {
/* Exits */
}
clearerr(f) ;
while ( ( a=getc(f) ) != EOF ) {
/* Do stuff */
}
if ( ferror(f) ) {
/* Exits */
}
Is the call to clearerr() necessary ?
I don't believe so.
If ferror() returns 0 can one be reasonably certain that the whole
file has been read ?
Within the constraints of Standard C, I think that might be a reasonable
conclusion.
I generally test explicitly with feof() as well, even if ferror()
returns false. Just a habit.