Need help with Record Update
Im trying to Update a Record that is inside a Text file.
I wish to do the Following,
Search for the Seat No.
once that is found ask user to enter new Name
New name will then Replace the Old name inside the text file.
Code:
long begin;
int location = 0;
fstream myFile("AirLine.text", ios::in | ios::out | ios::app | ios::binary);
begin = myFile.tellg();
cout << "Enter Passenger Seat Number:";
cin >> key;
location = (stArray[i].seat_number -1)* sizeof(passenger);
myFile.seekp(location, ios::cur);
cout << " Enter Passengers New Name:";
cin >> stArray[i].Newname;
myFile << stArray[i].Newname;
for (i=0; i<N_PASSENGER; i++)
{
if (stArray[i].seat_number == key)
stArray[i].name = stArray[i].Newname;
myFile << stArray[i].Newname;
}
cout << "Passengers name is now " << stArray[i].Newname;
}
myFile.close();
Code:
struct passenger
{
int seat_number;
string name;
string Newname;
string connecting_flight;
};
int N_PASSENGER;
struct passenger stArray[30];