C program Convert upper to lower case and vice versa is a program to convert the upper to lower case and vice versa in c. This is a program for case conversion.

String in c
String in c is a collection of characters. And it ends with the null character.
In c string has different string functions such as strcmp, strrev, strlen, strcpy, toupper and tolower, etc.

toupper in c :
To convert the alphabet to an upper case we use toupper() in c.
The syntax for toupper method in c
toupper (character);
Example :-
toupper (‘a’);
This will convert a to upper case alphabet that is A.

tolower in c :
To convert the alphabet to lower case we use tolower() in strings.
The syntax for tolower method in c
tolower (character);
Example :-
toupper (‘A’);
This will convert A to upper case alphabet a.

Algorithm to convert upper case to lower in c

  1. Declare variable. str
  2. Take string input from user
  3. Traverse the string
    If str[char] == uppercase
    tolower(str[char])
    If str[char] == lowercase
    toupper(str[char])
  4. Print converted string

C program to convert upper to lower case and vice versa using string function

#include<stdio.h>

#include<string.h>

#include<ctype.h>

main()

{
int i;
char str1[100];

printf("Enter a sentence to convert upper to lower and vice versa\n");

gets(str1);

for(i=0;i<strlen(str1);i++)

{

if(islower(str1[i]))

{

printf("%c",toupper(str1[i]));

}

else if(isupper(str1[i]))

{

printf("%c",tolower(str1[i]));

}

else

{

printf("%c",str1[i]);

}

}

}

Output :

C program Convert upper to lower case and vice versa

Write A Comment