Question : function that changes all lowercase letters of a string to uppercase.
Answered by : afolabi-adetunji
char *string_toupper(char *s)
{ int i; while( s[i] != '\0' ) { // if character is in lowercase // then subtract 32 if( s[i] >= 'a' && s[i] <= 'z' ) { s[i] = s[i] - 32; } // increase iterator variable i++; } return (s); }
Source : https://www.knowprogram.com/c-programming/convert-lowercase-to-uppercase/ | Last Update : Fri, 22 Jul 22
Question : convert uppercase to lowercase
Answered by : chakka-phani-simha
// C++ program to convert whole string to
// uppercase or lowercase using STL.
#include<bits/stdc++.h>
using namespace std;
int main()
{
// su is the string which is converted to uppercase
string su = "Jatin Goyal";
// using transform() function and ::toupper in STL
transform(su.begin(), su.end(), su.begin(), ::toupper);
cout << su << endl;
// sl is the string which is converted to lowercase
string sl = "Jatin Goyal";
// using transform() function and ::tolower in STL
transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
cout << sl << endl;
return 0;
}
Source : https://www.geeksforgeeks.org/conversion-whole-string-uppercase-lowercase-using-stl-c/ | Last Update : Sat, 30 Apr 22
Question : onvert it to lower case letter if it’s an upper case letter and convert it to upper case letter if it’s a lower
Answered by : ameer-jamal
#include<iostream>
#include<string>
using namespace std;
int main()
{ string str="Hello World"; int i; cout<<"The String is: \n"<<str; cout<<endl<<endl; cout<<"String after uppercase lowercase modification: \n"; for(i=0; i < str.length(); i++) { //if its uppercase add to its Ascii code 32 to make lowercase if(str[i]>='A' && str[i]<='Z') cout<<char(str[i]+32); // else if its lowercase subtract 32 to make it upper case else if(str[i]>='a' && str[i]<='z') cout<<char(str[i]-32); // else if its a space or symbol for example just print it as is else cout<<str[i]; //the reason this works is that the distance in Ascii from uppercase to lowercase //is standard and constant } return 0;
}
Source : | Last Update : Sat, 03 Sep 22