- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to convert upper case to lower and vice versa by using string concepts
Converting upper to lower and lower to upper is generally termed as toggle.
Toggle each character means, in a given string, the lower letter is print in upper form and upper case is print in lower letter respectively.
Program
The C program to convert upper case to lower and lower case to upper is given below −
#include <stdio.h> #define MAX 100 void toggle(char * string); int main(){ char string[MAX]; printf("enter the string need to be toggle :
"); gets(string); toggle(string); printf("final string after toggling is:
"); printf("%s
", string); return 0; } void toggle(char * string){ int i=0; while(string[i]!='\0'){ if(string[i] >= 'a' && string[i] <= 'z'){ string[i] = string[i] - 32; } else if(string[i] >= 'A' && string[i] <= 'Z'){ string[i]= string[i] + 32; } i++; } }
Output
When you run the above mentioned program, you will get the following output −
enter the string need to be toggle : TutoRialS PoinT C ProgrAmmIng LanGuage final string after toggling is: tUTOrIALs pOINt c pROGRaMMiNG lANgUAGE
Program
The C program to convert upper to lower and lower to upper by using the pre-defined function is as follows −
#include <stdio.h> int main(){ int i, length = 0; char string[] = "TutORial"; length = sizeof(string)/sizeof(string[0]); for(i = 0; i < length; i++){ if(isupper(string[i])){ string[i] = tolower(string[i]); } else if(islower(string[i])){ string[i] = toupper(string[i]); } } printf("final string after conversion: %s", string); return 0; }
Output
The output is as follows −
final string after conversion : tUTorIAL
- Related Articles
- How to convert Lower case to Upper Case using C#?
- How to convert Upper case to Lower Case using C#?
- Convert vowels from upper to lower or lower to upper using C program
- Convert string to DateTime and vice-versa in Python
- C++ Program to Convert Binary Number to Octal and vice-versa
- C++ Program to Convert Binary Number to Decimal and vice-versa
- C++ Program to convert Octal Number to Decimal and vice-versa
- Java Program to Convert the ArrayList into a string and vice versa
- How to convert String to StringBuilder and vice versa Java?
- How to replace upper triangular matrix with lower triangular matrix and vice versa in R?
- C# program to count upper and lower case characters in a given string
- C++ Program to Convert Km/hr to miles/hr and vice versa
- Convert a C++ String to Upper Case
- Converting string to number and vice-versa in C++
- Java program to count upper and lower case characters in a given string

Advertisements