Read.h


This method fills the input buffer with input book records. It contains two chunks of code:
~wenchen/public_html/cgi-bin/351/week5/Read.h

#include  <fstream>
#include  <cstdlib>
#include  <cstring>
  using namespace  std;

const  int  minRecordLen = 80;


int  TextBuffer::Read( fstream& stream ) {
  long    length, current;
  static  int  count = 0;

  Clear( );
  if ( stream.eof( ) )  return( bufferSize );
  current = stream.tellg( );
  stream.seekg( 0, fstream::end );
  length  = stream.tellg( );
  length -= current;
  if ( length < minRecordLen )  return( bufferSize );
  if ( length > maxBytes )
    length = maxBytes;
  stream.seekg( current, fstream::beg );
  stream.read ( buffer, length );
  cout << "Disk I/O number = " << ++count << endl << endl << endl;

  for ( int i = length - 1;  i > minRecordLen;  i-- )
    if ( strncmp( buffer+i-7, "</book>", 7 ) == 0 ) {
      bufferSize = i;
      break;
    }
  return( bufferSize );
}

The const keyword can be used to tell the compiler that a certain variable should not be modified once it has been initialized.