 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
Advertisements
 