-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (63 loc) · 1.49 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (63 loc) · 1.49 KB
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
#include <iostream>
#include<cstring>
#include<string>
using namespace std;
void trim(char *ptr){
uint64_t num_space = 0;
for(uint64_t i = 0 ; i<strlen(ptr); ++i){
if(ptr[i] == ' '){
++num_space;
uint64_t te = i;
uint64_t ch = i;
while(ch<strlen(ptr)){
if(ptr[ch+1] != ' '){
ptr[te] = ptr[ch+1];
++te;
}
else{
++num_space;
}
++ch;
} ///
break;
}
}
num_space = ((strlen(ptr)+num_space) - num_space)+1;
ptr[num_space] = '\0';
}
void trim(string *ptr){
uint64_t num_space = 0;
for(uint64_t i = 0 ; i<ptr->length()+1; ++i){
if((*ptr)[i] == ' '){
++num_space;
uint64_t te = i;
uint64_t ch = i;
//ptr->length()+1
while(ch<ptr->length()+1){
if((*ptr)[ch+1] != ' '){
(*ptr)[te] = (*ptr)[ch+1];
++te;
}
else{
++num_space;
}
++ch;
} ///
break;
}
}
for(int i = (ptr->length() - num_space); i<ptr->length(); ++i){
(*ptr)[i] = NULL;
}
}
int main()
{
/// c string Test.....
char test[] = "c++ is the best";
trim(test);
cout<<test<<endl;
///string Test...........
string test2 = "c++ is the best";
trim(&test2);
cout<<test2<<endl;
}