Slide 8.12: Bubblesort.h
Slide 10.1: Programming Exercise II: an on-line music store using a database
Home

WriteFile.h


The code below creates a new file in key order and replaces the input file by the newly created file.
 ~wenchen/public_html/cgi-bin/351/week8/WriteFile.h 
#include  <fstream>
#include  <iostream>
#include  <cstdlib>
  using namespace  std;

#include  "FixedLen_1.h"


void WriteFile( fstream& infile, char rrn[ ], int number, int length ) {
  fstream  outfile;
  char     buffer[MaxStr];

  outfile.open( "temp.txt", fstream::out );
  outfile << FixedLen( number, buffer, 6 );
  outfile << FixedLen( length, buffer, 5 ) << '\n';
  for ( int i = 0;  i < number;  i++ ) {
    infile.seekg ( 12+rrn[i]*length, fstream::beg );
    infile.read  ( buffer, length );
    outfile.write( buffer, length );
  }
  system( "mv temp.txt books.txt" );
  outfile.close( );
}