-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanging case of all characters.cpp
More file actions
54 lines (40 loc) · 1.33 KB
/
changing case of all characters.cpp
File metadata and controls
54 lines (40 loc) · 1.33 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
// Program to change the case of all characters in a string
#include<iostream>
using namespace std;
int main()
{
char string[100];
cout << "Enter any string:- " << endl;
cin.get(string,100);
for(int i=0; string[i]!='\0'; i++)
{
if(islower(string[i]))
{
string[i] = char(toupper(string[i]));
}
else
{
string[i] = char(tolower(string[i]));
}
}
cout << "The new string is " << string << endl;
}
/* islower():-
This function is used to check if a character is lowercase or not.
It is defined as:-
int islower ( int c );
It returns zero if the result is false, any other number otherwise.
toupper():-
This function is used to convert a lowercase letter to uppercase.
It is defined as:-
int toupper ( int c );
It takes the character to be converted as the parameter and cast it to an integer.
The return value is the uppercase equivalent of c.
It returns int representation of the uppercase if it exists.
Else, it returns the integer representation of the same argument character.
tolower():-
This function is used to convert an uppercase letter to lowercase.
It is defined as:-
int tolower ( int c );
Similar to toupper, it converts c to its lowercase equivalent and returns the value as an integer.
Both toupper and tolower method return the integer representation of a character. We can implicitly cast it to a character.*/