Home » Blog » Reverse The Case Of Input Character

Reverse The Case Of Input Character

getchar() is similar to scanf(). islower() is system defined function under ctype.h header file which check if the character is in lowercase or not. toupper() converts the input parameter into equivalent uppercase char. putchar() is similar to printf().

#include<stdio.h>
#include<conio.h>
#include<ctype.h> // for use system defined function islower() & toupper()

void main()
{
    char alphabet;
	
    clrscr();
	
    printf("Enter an alphabet : ");
    putchar('\n');  // to move to next Line

    alphabet=getchar();

    printf("\n\nReverse case of %c is :  ",alphabet);

    if(islower(alphabet))
	{
        putchar(toupper(alphabet));
    }
    else 
    {
        // must be an uppercase character
        printf("%c",tolower(alphabet)) ;
    }
    getch();
}

OutPut

Enter an alphabet : 

s


Reverse case of s is :  S

 

Leave a Reply

Your email address will not be published.