I have posted the update member function as many the 12th students can copy my project. I want to open the binary file compare the roll numbers with the inputted roll if it matches the object of the file should be overwritten with a new object i.e *X.
void Report_card :: Update()
{
cleardevice();
settextstyle(4,HORIZ_DIR,3);
setbkcolor(15);
setcolor(BLUE);
one_by_one(50,2,".....|| Update Records ||.....",3,100);
settextstyle(0,HORIZ_DIR,1);
int Ro;
long file_pos;
Report_card T,*X;
OXY(5,70,"Enter the roll number of the student whose record is to be edited :");
Ro = Inp_integer(5,90); // graphical input
fstream file;
file.open("report.txt",ios::in|ios::out|ios::ate);
if(!file)
{
OXY(5,110," Error in opening the file ! ");
getch();
}
while(file.read((char*)&T,sizeof(T)))
{
file.read((char*)&T,sizeof(T));
if (Ro == T.roll)
{
//OXY is outtextxy's name changed using a macro.
OXY(1,120," Enter the name of the student : ");
Inp_string(500,120,X->name);
OXY(1,140," Enter the marks in Physics : ");
X->mark[0] = Inp_integer(500,140);
OXY(1,160," Enter the marks in Chemistry : ");
X->mark[1] = Inp_integer(500,160);
OXY(1,180," Enter the marks in Maths : ");
X->mark[2] = Inp_integer(500,180);
OXY(1,200," Enter the marks in English : ");
X->mark[3] = Inp_integer(500,200);
OXY(1,220," Enter the marks in C++ : ");
X->mark[4] = Inp_integer(500,220);
file.write((char*)&(*X),sizeof(*X));
getch();
file.close();
break;
}
else
{
OXY(5,110,"Roll not found !");
delay(1000);
}
}
}
the program just exits after inputting Ro. :(