Well, all you really needed to do was to take the existing (working) code and cut+paste it into your new functions. Very minor changes would be required that way.
As it is, the latest code seems to have taken several steps backwards. For example here:
84 85 86 87 88 89 90 91 92 93 94
|
void DisplayP()
{
fstream fil;
fil.open("ITEM.TXT",ios::in|ios::binary);
fil.read((char*)&itm, sizeof(itm));
while(!fil.eof())
{
itm.showdata();
}
fil.close();
}
|
Lines 89 to 92 look pretty much like an infinite loop to me.
And just picking another line from the code here, line 105:
if(strcmp(in,itm.getino())==0)
both
in
and the value returned by
getino()
are integers, so why they would be compared as c-strings is beyond me.
Just taking a step back for a moment, to an earlier version:
http://www.cplusplus.com/forum/beginner/115239/#msg629090
There was an error I overlooked. At line 105:
100 101 102 103 104 105 106
|
fstream fio(filename,ios::in|ios::out|ios::binary);
cout<<"Enter The Item Number To Modify : "<<endl;
cin>>in;
while(fio.read((char*) &i ,sizeof(i)))
{
fio.read((char*) &i ,sizeof(i)); // this line is not needed
if (i.getino()==in)
|
The file is being read twice in the loop, once as part of the while condition, and again in the body of the loop. The second read (at line 105) is not needed.