
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C Program for LowerCase to UpperCase and vice-versa
Here is the program to convert a string to uppercase in C language,
Example
#include <stdio.h> #include <string.h> int main() { char s[100]; int i; printf("\nEnter a string : "); gets(s); for (i = 0; s[i]!='\0'; i++) { if(s[i] >= 'a' && s[i] <= 'z') { s[i] = s[i] - 32; } } printf("\nString in Upper Case = %s", s); return 0; }
Output
Here is the output
Enter a string : hello world! String in Upper Case = HELLO WORLD!
In the above program, the actual code of conversion of string to upper case is present in main() function. An array of char type s[100] is declared which will store the entered string by the user.
Then, for loop is used to convert the string into upper case string and if block is used to check that if characters are in lower case then, convert them in upper case by subtracting 32 from their ASCII value.
for (i = 0; s[i]!='\0'; i++) { if(s[i] >= 'a' && s[i] <= 'z') { s[i] = s[i] -32; } }
Here is the program to convert a string to lowercase in C language,
Example
#include <stdio.h> #include <string.h> int main() { char s[100]; int i; printf("\nEnter a string : "); gets(s); for (i = 0; s[i]!='\0'; i++) { if(s[i] >= 'A' && s[i] <= 'Z') { s[i] = s[i] + 32; } } printf("\nString in Lower Case = %s", s); return 0; }
Output
Here is the output
Enter a string : HELLOWORLD String in Lower Case = helloworld
In the above program, the actual code of conversion of string to lowercase is present in main()function. An array of char type s[100] is declared which will store the entered string by the user.
Then for loop is used to convert the string into lower case string and if block is used to checkthat if characters are in uppercase then, convert them in lowercase by adding 32 to their ASCII value.
for (i = 0; s[i]!='\0'; i++) { if(s[i] >= 'A' && s[i] <= 'Z') { s[i] = s[i] + 32; } }
- Related Articles
- Return element-wise a copy of the string with uppercase characters converted to lowercase and vice versa in Numpy
- 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
- C++ Program to Convert Km/hr to miles/hr and vice versa
- Converting string to number and vice-versa in C++
- Java program to convert a string to lowercase and uppercase.
- Golang program to convert the arraylist into string and vice-versa
- Program to convert speed in km/hr to m/sec and vice versa in C++
- C program to convert upper case to lower and vice versa by using string concepts
- Binary to decimal and vice-versa in Python
- Java Program to Convert the LinkedList into an Array and vice versa
- Java Program to Convert the ArrayList into a string and vice versa
- Convert from any base to decimal and vice versa in C++
- How to convert an integer to hexadecimal and vice versa in C#?
