-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrings and Array
129 lines (94 loc) · 2.64 KB
/
Strings and Array
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
#include <iostream>
#include<string.h>
using namespace std;
//checking the length of string without using strlen function
int getLength(char name[]) {
int length = 0;
int i = 0;
while(name[i] != '\0') {
length++;
i++;
}
return length;
}
//Using two pointers approach to reverse a string
void reverseCharArray(char name[]) {
int i = 0;
int n = getLength(name);
int j = n - 1;
while(i<=j) {
swap(name[i], name[j]);
i++;
j--;
}
}
void replaceSpaces(char sentence[ ]){
int i = 0;
int n = strlen(sentence);
for(int i=0; i<n; i++) {
if(sentence[i] == ' ') {
sentence[i] = '@';
}
}
}
bool checkPalindrome(char word[] ) {
int i=0;
int n = strlen(word);
int j = n - 1;
while(i <= j) {
if(word[i] != word[j]) {
return false;
}
else {
i++;
j--;
}
}
return true;
}
void convertIntoUpperCase(char arr[]) {
int n = getLength(arr);
for(int i=0; i<n; i++) {
arr[i] = arr[i] -'a' + 'A';
}
}
int main() {
char name[100];
cout<< "Enter your Name " << endl;
cin >> name;
cout << "Aapka naam: " << name << " hai " << endl;
char ch[100];
ch[0] = 'a';
ch[1] = 'b';
cin >> ch[2];
cout << ch[0] << ch[1] << ch[2] << endl;
char name[100];
cin >> name;
for(int i=0; i<7; i++) {
cout << "index: " << i << " value: " << name[i] << endl;
}
int value = (int)name[6];
cout << "value is : " << value << endl;
char arr[100];
cin >> arr;
getline(cin, arr);
cin.getline(arr, 50);
cout << arr;
char name[100];
cin >> name;
cout << "length is: " << getLength(name) << endl;
cout << "Length is -> " << strlen(name) << endl;
cout << "Initially: " << name << endl;
reverseCharArray(name);
cout << "After reversal process: " << name << endl;
char sentence[100];
cin.getline(sentence, 100);
replaceSpaces(sentence);
cout << "printing sentence " << endl << sentence << endl;
char arr[100] = "hahahahha";
cout << "palindrome check: " << checkPalindrome(arr);
char arr[100] = "babbar";
convertIntoUpperCase(arr);
cout << arr << endl;
return 0;
}