|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
/* ... */
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 ? If ferror() returns 0 can one be reasonably certain that the whole file has been read ? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
In article
<e949195b-e2e6-4922-9ebf-afa412746d5f@b32g2000hsa.googlegroups.com>, Spiros Bousbouras <spibou@gmail.com> wrote 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. |
|
![]() |
| Outils de la discussion | |
|
|