#include #include #include int main( int argc, char *argv[] ) { unsigned BytesInFile; unsigned BytesPerRecord = 4; unsigned Records; if( argc != 2 ) { cout << "Usage: sortit " << endl; return 1; } fstream in; in.open( argv[1], ios::in | ios::out | ios::binary ); if( !in ) { cout << "Error opening " << argv[1] << endl; return 1; } in.seekg( 0, ios::end ); BytesInFile = in.tellg(); Records = BytesInFile / BytesPerRecord; cout << "Bytes In File: " << BytesInFile << endl; cout << "Number of Records: " << Records << endl; cout << "BytesPerRecord: " << BytesPerRecord << endl; int x, y, i, j; for( i = 0; i < Records - 1; i++ ) { for( j = 0; j < Records - 1; j++ ) { in.seekg( j * BytesPerRecord, ios::beg ); in >> x; in.seekg( j * BytesPerRecord + 4, ios::beg ); in >> y; //cout << "x: " << x << " y: " << y << endl; //getchar(); if( x > y ) { in.seekp( j * BytesPerRecord, ios::beg ); in << y << endl; in.seekp( j * BytesPerRecord + 4, ios::beg ); in << x << endl; } } } in.close(); return 0; }