UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to convert uppercase to lowercase and lowercase to uppercase

C program for how to convert a string lower case to upper case and upper case to lower case.

by Krishna viswambharan


Posted on 20 Oct 2017 Category: C Views: 169

Edited on 24 Mar 2018


C program to convert uppercase to lowercase and vice-versa

Here is the source code of the C program to replace lowercase characters by uppercase & vice-versa. The program output is also shown below.

The C library function  “toupper()” converts lowercase letter to uppercase. Similarly “tolower()” converts uppercase letter to lowercase .

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
void main()
{
       char name[50];
       int i=0;
       printf(“Enter the string :”);
       gets(name);
       if(isupper(name[0]))
	        name[0]=tolower(name[0]);
       else
	        name[0]=toupper(name[0]);
       while(name[i]!=’\0’)
       {
	        if(isupper(name[i+1]))
		           name[i+1]=tolower(name[i+1]);
	        else
		          name[i+1]=toupper(name[i+1]);
	        i=i+1;
       }
       puts(name);
       getch();
}

 

output

 



Leave a Comment:


Advertisement