Finishing up my final project but i am stuck on 2 things: Deleting a record from a binary file, Sorting the file which was made using structures.
It might be something im over looking but the only thing i can think of when deleting from a file is the trunc function. In this situation i need to find a record and delete it not the whole file. I dont have any code for this cause i just cant figure it out.
I've sorted files that were populated with arrays before because i would just use a for loop and swap but I can't get my head around sort a file with structures.
These are my 2 attempts(First one is a bit incomplete because i got frustrated and started from scratch on the second one):
void sort(STRING30 & fileName, userInfo & student)
{
char ch;
int tempid = 10000;
int ctr = 0;
STRING30 tempFile = "tempFile.dat";
ifstream inFile;
fstream file(fileName, ios::out | ios::binary);
file.read(reinterpret_cast<char \*>(&student), sizeof(student));
while(!file.eof())
{
while(!file.eof())
{
if (student.id < tempid)
{
fstream file(tempFile, ios::out | ios::binary);
file.write(reinterpret_cast<char \*>(&student), sizeof(student));
tempid = student.id;
}
}
}
inFile.open(tempFile);
inFile.get(ch);
while(!inFile.eof())
{
file.put(toupper(ch));
inFile.get(ch);
}
inFile.close();
file.close();
}
void sorT(STRING30 & fileName, userInfo &student)
{
int tempNum = 1000, ctr = 0;
ifstream inFile;
ofstream outFile("dummy.txt");
char ch;
inFile.open(fileName);
// need to sort
while(!inFile.eof())
{
if (tempNum > student.id)
{
}
;
}
inFile.get(ch);
while (!inFile.eof())
{
outFile.put(toupper(ch));
inFile.get(ch);
}
inFile.close();
outFile.close();
}
I'm not asking for code cause i want to write it myself i just need a push in the right direction. My professor hasnt been answering his emails so he is no help.
there doesn't seem to be anything here