-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.cpp
More file actions
111 lines (72 loc) · 1.07 KB
/
string.cpp
File metadata and controls
111 lines (72 loc) · 1.07 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
96
97
98
99
100
101
102
103
104
105
#include<iostream>
using namespace std;
class String
{
char a[100];
public:
void getstring(char* y)
{
int i;
for(i = 0; y[i]!='\0';i++)
{
a[i]=y[i];
}
a[i] = '\0';
}
void putstring()
{
int i;
for(i = 0; a[i]!='\0'; i++)
{
cout<< a[i];
}
}
int str_length()
{
int i;
int len = 0;
for(i = 0; a[i]!= '\0'; i++)
{
++len;
}
return len;
}
int str_cmp(String s)
{
int flag = 0;
for(int i = 0; s.a[i]!='\0';i++)
{
if(this->a[i] != s.a[i])
{
flag = 1;
break;
}
}
return flag;
}
};
int main()
{
int k, i;
int flag;
char string[100];
cout<<"Enter the string";
cin>>string;
char string1[100];
cout<<"Enter the string";
cin>>string1;
String str1;
String str2;
str1.getstring(string);
str2.getstring(string1);
cout<<"\n";
str1.putstring();
cout<<"\n";
k = str1.str_length();
cout<<"The length is : "<<"\n"<<k;
flag = str1.str_cmp(str2);
cout<<"\n";
cout<<flag;
cout<<"\n";
return 0;
}