In this tutorial you will learn about the C program to Convert String to Uppercase and its application with practical example.
C Program to Convert String to Uppercase
In this tutorial, we will learn to create a C program that will Convert String to Uppercase in C programming.
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C programming.
- Conditional Statements in C programming.
What is a String?
The String is a collection character. The character is a single entity in the English language or in any word. These characters can be any alphabets in lower case or upper case.
The lower case means the small letters. And the upper case means the capital letters of the English language.
In the string “Hello”, there are five characters, they are as follows
‘H’ is a character in the Upper case.
‘e’ is a character in the lower case.
‘l’ is a character in the lowercase.
‘l’ is a character in the lower case.
‘o’ is a character in the lowercase.
1. Declaring the variables for the program.
2. Taking the input String from the user.
3. Passing that variable to conditional statements.
4. Using those conditions to Convert the String to Uppercase.
5. Printing the resultant String to the user.
6. End The Program.
Program to Convert String to Uppercase
First, we will take the input string from the user. Then will pass that String in the conditional statements to check and convert it into the Upper case String.
With the help of this program, we can convert that String to upper case.
C Program to Convert <strong>String</strong> to Uppercase **
//declaring the required variables for the program.
//taking the input string from the user.
printf("\nEnter a string : ");
//Checking and converting the string to upper case.
for (i = 0; str[i]!='\0'; i++)
if(str[i] >= 'a' && str[i] <= 'z')
str[i] = str[i] -32;
//Printing the output string
printf("\nString in Upper Case = %s", str);
In the above program, we have first initialized the required variable.
- str = it will hold the String value for the input.
- i = it will hold the integer value for the loop.
Input String from the user.
Checking the given String and converting it into an upper case String.
Printing uppercase String.