-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDFP0-VIN.CPP
executable file
·136 lines (105 loc) · 3.61 KB
/
DFP0-VIN.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************
DFP0-VIN.cpp - DataFormatProgram0 like DFP1, but without vectors
this prog takes in a text file, opens it, reads it line by line,
then reconstructs / outputs
*******************************/
# include <iostream.h>
# include <string>
# include <fstream.h>
/************************FUNCTIONS***************************/
void ChopLineUp();
void CleanModel();
void CleanVIN();
void PutTogether();
void PrintLine();
/****************************STRINGS**************************/
string line, YR, MAKE, MODEL, VIN;
//Constants:
string MT(""), dot("."), CUTMAKE(" MAKE\t"), CUTID("ID#\t"), TAB("\t"), NL("\n");
/********************Files for input & output****************/
ifstream infile("vinin.txt");
ofstream outfile("vinout.txt");
//files needs to be in the same dir as the exe
int main(){
/*strupr and lwr only works on chars?
getline(infile, line);
strupr(line);
cout<<"line1 upperd: "<<line+NL;
strlwr(line);
cout<<"line1 lowerd: "<<line+NL;
getline(infile, line);
strupr(line);
cout<<"line2 upperd: "<<line+NL;
strlwr(line);
cout<<"line2 lowerd: "<<line+NL;
*/
while( getline(infile, line) ) {
// read lines until end of file
if (line.substr(2,1)==" "){
ChopLineUp();
CleanModel();
CleanVIN();
//outfile<<"YR: "<<YR<<".\nMAKE: "<<MAKE<<".\nMODEL: "<<MODEL<<".\n"<<"VIN: "<<VIN<<".\n";
PutTogether();
PrintLine();
cout<<dot;
}
}
infile.close(); //this doesnt seem necessary, nor harmful
outfile.close();
return 0;
}
void ChopLineUp(){
//comes in like this:
// 91 MAKE ACURA LEGEND ID# JH4KA7661MC039256
//
int size=line.size(), pos, msize;
YR=line.substr(0,2);
line=line.substr(8,size-8);//line is now line minus YR and CUTMAKE
//IE :"MAKE?^MODEL?^?ID#\tVIN?"
pos=line.find(" ");
MAKE=line.substr(0,pos);//make found; chop line down;
size=line.size();
line=line.substr(pos+1,size-1); //line:"MODEL?^?ID#\tVIN?"
pos=line.find("ID#\t");
MODEL=line.substr(0,pos); //model found (but not cleaned yet)...
size=line.size();
line=line.substr(pos+4,size-1);//line:"VIN?^?"
VIN=line;
}
void CleanModel(){
int size=MODEL.size();
int pos=MODEL.find_last_of(" ");
//outfile<<"MODEL B4: "<<MODEL<<".\n";
for (int i=size;i>0;i--){
if (pos>=(size-1)){
MODEL=MODEL.substr(0,size-1);
//outfile<<"MODEL during: "<<MODEL<<".\n";
size=MODEL.size();
pos=MODEL.find_last_of(" ");
}
}
//outfile<<"MODEL after: "<<MODEL<<".\n";
}
void CleanVIN(){
int size=VIN.size();
int pos=VIN.find_last_of(" ");
if (pos!=-1){
//outfile<<"VIN B4: "<<VIN<<".\n";
for (int i=size;i>0;i--){
if (pos>=(size-1)){
VIN=VIN.substr(0,size-1);
//outfile<<"VIN during: "<<VIN<<".\n";
size=VIN.size();
pos=VIN.find_last_of(" ");
}
}
//outfile<<"VIN after: "<<VIN<<".\n";
}
}
void PutTogether(){
line=YR+TAB+MAKE+TAB+MODEL+TAB+VIN;
}
void PrintLine(){
outfile<<line<<endl;
}