Why while loop is used?
int count=0, total = 0;
char bufferd[100];
FILE *stream;
//FILE *outstream;
if( (stream = fopen( "feof.txt", "a+" )) == NULL )
exit( 1 );
/* Cycle until end of file reached: */
while( !feof( stream ) )
{
count = fread( buffer, sizeof( char ), 100, stream );
cout<<buffer;
if( ferror( stream ) ) {
perror( "Read error" );
break;
}
/* Total up actual bytes read */
total += count;
}
I think the code below performs the same action without while loop.
int count=0, total = 0;
char bufferd[11];
FILE *stream;
//FILE *outstream;
if( (stream = fopen( "feof.txt", "a+" )) == NULL )
exit( 1 );
count = fread( buffer, sizeof( char ), 100, stream );
cout<<buffer;
if( ferror( stream ) ) {
perror( "Read error" );
}
/* Total up actual bytes read */
total += count;


Sign In
Create Account


Back to top









