-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDynamicPointerArray.cpp
94 lines (61 loc) · 1.33 KB
/
DynamicPointerArray.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
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
class Lib{
public:
int Count(string str,char delimit){
//\0 stand for end of text(line).
static int panjang;
for(int x =0; str[x]!='\0'; x++){
if(str[x] == delimit){
panjang++;
}
}
return panjang;
}
//splitter atau delimiter pembagi antar item array.
int* SplitInit(string std,char delimiter){
stringstream str;
//get length
int counter = Count(std,delimiter);
//use malloc for allocationg memory.
int *A;
//for loop
int temp =0;
for(int x =0; x < counter; x++){
if(std[x]==delimiter){
str << string(1,std[x-1]);
str >> temp;
A[x-1]=temp;
}
}
return A;
}
};
class DynamicIntArrayz: public Lib{
public:
void getNumber(string arr){
}
};
int main(){
Lib dynamicArray;
int *p;
string arr = "26 40 60 70 ";
int x =dynamicArray.Count(arr,' ');
cout << "Length: " <<x << endl;
p = (int*)malloc(x * sizeof(int));
string S,T;
stringstream X(arr);
int c =0;
while(getline(X,T,' ')){
p[c] = stoi(T);
c++;
}
for(int de = 0; de < x; de++){
cout << p[de]<<endl;
}
return 0;
}