1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
void Records::editInfo(Info &entries, char *fName, int f_size)
{
long posNum;
string input;
fstream recordsFile("records.dat", ios::in | ios::out | ios::binary);
recordsFile.read(reinterpret_cast<char *>(&entries), sizeof(entries));
while (!recordsFile.eof())
{
position = recordsFile.tellg();
if(strcmp(entries.name, fName) == 0 || (strstr(entries.name, fName) != NULL))
{
cout << endl;
cout << position / sizeof(entries) << ". ";
cout << "Name found at position " << position << "!\n\n";
cout << entries.name << endl;
cout << entries.addr << endl;
cout << entries.city << endl;
cout << entries.state << endl;
cout << entries.zip << endl;
cout << entries.phone << endl;
cout << entries.acctBal << endl;
cout << entries.dateLP << endl;
cout << endl;
recordsFile.read(reinterpret_cast<char *>(&entries), sizeof(entries));
}
else
{
cout << "Name not found. \n";
recordsFile.read(reinterpret_cast<char *>(&entries), sizeof(entries));
}
}
cout << "Type the record number of the entry you would like to edit : ";
cin >> posNum;
cin.ignore();
cout << endl;
position = posNum * sizeof(entries) - sizeof(entries);
recordsFile.seekg(position, ios::beg);
recordsFile.read(reinterpret_cast<char *>(&entries), sizeof(entries));
cout << "\nWriting data to position " << position << " of file.\n";
//Get the new data from user.
cout << "NAME: ";
getline(cin, input);
strcpy_s(entries.name, input.c_str());
cout << "ADDRESS: ";
getline(cin, input);
strcpy_s(entries.addr, input.c_str());
cout << "CITY: ";
getline(cin, input);
strcpy_s(entries.city, input.c_str());
cout << "STATE: ";
getline(cin, input);
strcpy_s(entries.state, input.c_str());
cout << "ZIP: ";
getline(cin, input);
strcpy_s(entries.zip, input.c_str());
cout << "PHONE: ";
getline(cin, input);
strcpy_s(entries.phone, input.c_str());
cout << "ACCOUNT BALANCE: $";
cin >> entries.acctBal;
cin.ignore();
cout << "DATE OF LAST PAYMENT: ";
getline(cin, input);
strcpy_s(entries.dateLP, input.c_str());
recordsFile.seekp(position, ios::beg);
recordsFile.write(reinterpret_cast<char *>(&entries), sizeof(entries));
cout << "Record updated. ";
system("pause");
recordsFile.close();
}
|