Convert char from lowercase to uppercase

This program is about converting a lowercase English character to its corresponding uppercase character. It is a simple hack but the C built-in function toupper is definitely faster than this one.

Last Reviewed and Updated on October 26, 2017
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

Advertisement

Program to convert a lowercase character to uppercase.

Ask the user to enter an English character in lowercase. Write code to display it in uppercase.

int main()
{

    cout << "Enter lowercase character: ";

    char k;

    cin >> k;

    /*
    We have to add 'A' - 'a' to convert lowercase 'a'
    to uppercase 'A'. This same number should be
    added to every lowercase character
    to change it to its corresponding uppercase character.
    */
    char output = k + ('A' - 'a');

    cout << "Uppercase = " << output << endl;

    return 0;

}


My C/C++ Videos on Youtube

Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.



Creative Commons License
This Blog Post/Article "Convert char from lowercase to uppercase" by Parveen (Hoven) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Updated on 2017-10-26.


Advertisement