Thursday, March 4, 2021
Home C / C++ Converting lowercase to uppercase in C++

Converting lowercase to uppercase in C++

Here we are converting lowercase to uppercase in C++ by using an additional library in our includes;Here is a code which is able of converting a string from lowercase to uppercase:

  1. // converting lowercase to uppercase in C++
  2. #include <iostream>
  3. #include <cctype>
  4. using namespace std;
  5. void convertToUppercase( char * );
  6.  
  7. int main()
  8. {
  9.     char phrase[] = “characters and $32.98”;
  10.     cout << “The phrase before conversion is: “ << phrase;
  11.     convertToUppercase( phrase );
  12.     cout << “nThe phrase after conversion is:  “
  13.         << phrase << endl;
  14.     return 0;  // indicates successful termination
  15. }
  16.  
  17. // convert string to uppercase letters
  18. void convertToUppercase( char *sPtr )
  19. {
  20.     while ( *sPtr != ‘’ ) {   // current character is not ‘’
  21.         if ( islower( *sPtr ) )  // if character is lowercase,
  22.             *sPtr = toupper( *sPtr );  // convert to uppercase
  23.         ++sPtr;  // move sPtr to next character in string
  24.     }
  25. }

in the above code we used an new library named “cctype”, then we defined a function which is includes the function of “islower” and “toupper” from the “cctype” library, then we selected a phrase from our main() and passed it to the function as an argument, and at the end we are done with converting lowercase to uppercase in C++.

 

2 COMMENTS

- Advertisment -

Most Popular

Android Webview Tutorial With Example | How to Use Webview in Android

Android Webview Tutorial With Example Have you seen an Android app displaying Web content using Webview. This Android Webview Tutorial is about integrating Webview using Android Studio....

Student Registration Project in PHP

In this Student Registration Project we are providing a form in simple html to the student and that form sends the data to "student.php"...

Java GUI Calculator Source Code

Here we have a Java GUI Calculator Source Code for you in which a Java GUI calculator has been created using "swing" and "awt". The calculator has...

Numeric Array in PHP

Numeric arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero....