Answer the question
In order to leave comments, you need to log in
How does while ( !feof ( cfPtr ) ) work?
FILE * cfPtr = fopen( "test.txt", "rb" );
char temp;
while ( !feof ( cfPtr ) ){
fread( &temp, sizeof( char ), 1, cfPtr );
printf("%c\n", temp);
}
A
B
C
C
Answer the question
In order to leave comments, you need to log in
How does while ( !feof ( cfPtr ) ) work?
FILE * cfPtr = fopen( "test.txt", "rb" );
char temp;
for (;;) {
int read = fread( &temp, sizeof( char ), 1, cfPtr );
if (read == 1) {
printf("%c\n", temp);
} else {
if (feof(cfPtr)) {
/*случился конец файла*/
} else if (ferror(cfPtr)) {
/* случилась ошибка */
}
break;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question