How to convert a lowercase/uppercase character in C ?

Monday, June 14, 2010

C08_Ex 2:  Enter one letter. If it is  uppercase character, changed to lowercase letters, changed back to uppercase.

// Input a character
// If It's a  upper-case character -> change into lower-case character
// If It's a  lower-case character -> change into upper-case character
// Use Visual Studio 2005

#include <stdio.h>

void main()
{
    char ch;
    printf("Input a character: ");
    scanf("%c", &ch);

    if (ch >= 'a' && ch <= 'z')
        ch = ch - 32;
    else
        if (ch >= 'A' && ch <= 'Z')
            ch = ch + 32;

    printf("=> Character after changing: %c\n", ch);
}

0 Comments:

Post a Comment

 
 
 
 
Copyright © 2010 C Source Code - C++ Source Code. All Rights Reserved. Using Xclear Theme | Bloggerized by Themescook Developed by Helios | Powered by Blogger