-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_case.cpp
More file actions
53 lines (41 loc) · 1.24 KB
/
string_case.cpp
File metadata and controls
53 lines (41 loc) · 1.24 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
#include <iostream>
using namespace std;
void to_upper() {
// Dynamically allocate memory for the input string
char* string = new char[1000];
cout << "Enter a string: ";
cin.getline(string, 1000);
// Convert the string to uppercase
cout << "Uppercase string: ";
for (int i = 0; string[i] != '\0'; ++i) {
if (string[i] >= 'a' && string[i] <= 'z') {
string[i] = string[i] - ('a' - 'A'); // Convert to uppercase
}
cout << string[i]; // Print the character
}
cout << endl;
// Free dynamically allocated memory
delete[] string;
}
void to_lower() {
char* string = new char[100];
cout << "Enter a string: ";
cin.getline(string, 100);
cout << "Lowercase string: ";
for (int i = 0; string[i] != '\0'; ++i) {
if (string[i] >= 'A' && string[i] <= 'Z') {
string[i] = string[i] + ('a' - 'A'); // Convert to lowercase
}
cout << string[i]; // Print the character
}
cout << endl;
// Free dynamically allocated memory
delete[] string;
}
int main() {
// Call the to_upper function
to_upper();
// Call the to_lower function
to_lower();
return 0;
}