-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.cpp
More file actions
46 lines (45 loc) · 948 Bytes
/
update.cpp
File metadata and controls
46 lines (45 loc) · 948 Bytes
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
#include"common.cpp"
inline void update(int n)
{
int notFound = 1;
char confirm;
inventory inv;
fstream fbj("TEST0.dat", ios::in | ios::out | ios::ate | ios::binary);
fbj.seekg(0);
if (!fbj)
{
cout << "FAILED TO OPEN FILE!";
_getche();
}
while (!fbj.eof())
{
fbj.read((char*)&inv, sizeof inv);
if (n == inv.serial())
{
notFound = 0;
cout << "RECORD FOUND:\n\n";
inv.output();
cout << "\n\nUpdate this item? (y/n) : ";
do
{
cin >> confirm;
if (confirm == 'n')
break;
if (confirm == 'y')
{
cout << "\n\nENTER NEW DETAILS:\n\n";
inv.input();
long x = fbj.tellp(), y = sizeof(inv);
fbj.seekp(x - y);
fbj.write((char*)&inv, sizeof inv);
cout << "\n\nRecord updated.\n\n";
break;
}
} while (confirm != 'y' || confirm != 'n');
break;
}
}
fbj.close();
if (notFound)
cout << "Record not found.\n";
}