-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateVehicle.cpp
64 lines (50 loc) · 1.28 KB
/
CreateVehicle.cpp
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
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include "VehicleFile.h"
using namespace std;
const int DATALENGTH = 25;
int main()
{
char InFile[] = "vehicle.data";
char OutFile[] = "vehicle.db";
char inBuffer[35];
int numberRecords;
ifstream inputFile;
ofstream outputFile;
numberRecords = 0;
inputFile.open(InFile);
if(!inputFile)
{
cerr << "Problem opening input file: " << InFile << endl;
return 1;
}
outputFile.open(OutFile);
if(!outputFile)
{
cerr << "Problem opening output file: " << OutFile << endl;
inputFile.close();
return 2;
}
while(true)
{
memset(inBuffer, ' ', sizeof(inBuffer));
inputFile.getline(inBuffer, sizeof(inBuffer));
if(inputFile.eof())
break;
outputFile.seekp((numberRecords+1)*DATALENGTH);
outputFile.write(inBuffer, DATALENGTH);
++numberRecords;
}
outputFile.seekp(0);
outputFile.write((char*) &numberRecords, sizeof(numberRecords));
inputFile.close();
outputFile.close();
VehicleFile * pVehicleFile = new VehicleFile;
pVehicleFile->SortBySSN();
delete pVehicleFile;
cout << "Number of records: " << numberRecords << endl;
cout << "Sorting..." << endl;
return 0;
}