Converting lowercase to uppercase in C++

0
433
C++ Program to find largest of 3 numbers
Fractional Calculator 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++.

 

C++ Program to find largest of 3 numbers
Fractional Calculator in C++

Leave a Reply