Hey guys im having a bit of trouble with bubble sorting an array from a file...
Basically what needs to be done is i need to read a text file into a struct array and then copy it into a new file after sorting it by a string field
can you help me please this is what i have so far
//--------------------------------------------------------------------------
// void
// Purpose:
// Inputs:
// Ouputs:
//---------------------------------------------------------------------------
void sort(int item[], int size)
{
clrscr();
int swaps;
int temp;
int left;
int right;
do
{
swaps = 0;
left = 0;
right = 1;
while (right < size)
{
if (item[ right ] < item [left])
{
temp = item[ left ];
item[ left ] = item[ right ];
item[ right ] = temp;
swaps++;
}
left++;
right++;
}
} while (swaps > 0);
getch();
}
//---------------------------------------------------------------------------
// void
// Purpose:
// Inputs:
// Ouputs:
//--------------------------------------------------------------------------
char archive()
{
clrscr();
fstream recordFile;
recordFile.open("H:\\records.txt", ios::binary | ios::out | ios::in);
fstream archiveFile;
participant person;
char confirm;
cout << "**********ARCHIVE A RECORD**********\n\n" ;
recordFile.seekg(0, ios::beg);
cout << "Are you sure you want to archive the file?";
cin >> confirm;
if (tolower(confirm) == 'y' || tolower(confirm) == 'yes')
{
archiveFile.open("H:\\archive.txt", ios::binary | ios::out );
archiveFile.close();
cout << "\nPlease wait while we archive the record...\n\n";
archiveFile.open("H:\\archive.txt", ios::binary | ios::in | ios::out);
recordFile.read((char*) &person, sizeof (participant));
while(!recordFile.eof())
{
archiveFile.write((char*) &person, sizeof(participant));
recordFile.read((char*) &person, sizeof (participant));
}
archiveFile.close();
cout << "\n---The file has been archived---";
return (person);
}
else
{
cout << "\n---You have chosen NOT to archive this folder---";
}
recordFile.close();
getch();
}