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
| #include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
struct database_attr{
int orderkey;
int custkey;
int totalprice;
int prior;
};
database_attr p[1024];
int main(){
fstream fin;
char buf[200];
string str[10][1001];
string data[5][1001];
int data1[5][1001];
int data2[5][1001];
fin.open("store_test.tbl");
int row = 0;
int col;
int n = 9;
while(!fin.eof()){
row = 0;
fin.getline(buf, 200, '\n');
for(int i = 0; buf[i] != '\0';){
if(buf[i] == '|' && n > 0){
row++;
i++;
n--;
}else if(buf[i] != '|' && n > 0){
str[row][col] += buf[i];
i++;
}
}
n = 9;
col++;
}
for(int i = 0; i < 9; i++){
for(int j = 0; j < 1000; j++){
// cout<<str[i][j]<<" ";
}
//cout<<endl;
}
//store the data in column
for(int i = 0; i < 9; i++){
for(int j = 0; j < 1000; j++){
if(i == 0){
data[i][j] = str[i][j];
}
if(i == 1){
data[i][j] = str[i][j];
}
if(i == 3){
data[i - 1][j] = str[i][j];
}
if(i == 7){
data[i - 4][j] = str[i][j];
}
}
}
for(int i = 0; i < 4; i++){
for(int j = 0; j < 1000; j++){
//cout<<data[i][j]<<" ";
}
//cout<<endl;
}
//check the data use the index
/*
int ok;
cin>>ok;
cout<<data[1][ok]<<" "<<data[2][ok]<<" "<<data[3][ok]<<endl;
*/
fin.close();
//change the string array into int array
int i, j;
for(i = 0; i < 4; i++){
for(j = 0; j < 1000; j++){
data1[i][j] = atoi(data[i][j].c_str());
}
}
for(i = 0; i < 4; i++){
for(j = 0; j < 1000; j++){
data2[i][j] = data1[i][j];
if(j < 10)
cout<<data2[i][j]<<" ";
}
cout<<endl;
}
//store the array into struct array
for(i = 0; i < 4; i++){
for(j = 0; j < 1000; j++){
p[j].orderkey = data2[0][j];
p[j].custkey = data2[1][j];
p[j].totalprice = data2[2][j];
p[j].prior = data2[3][j];
}
}
cout<<"The id 1 has "<<p[0].orderkey<<" "<<p[0].custkey<<" "<<p[0].totalprice<<" "<<p[0].prior<<endl;
return 0;
}
|