C Program to convert a string from lowercase to uppercase
|In this C Programming example, we will implement the program to convert a string from lower case to upper case and print the output on the screen.
1. String case Conversion – Lower Case to Upper Case
String Case Conversion is a process to convert each character of a string to either Uppercase or to Lowercase characters.
Example Enter the string which needs to be converted : happy birthday The String in Upper Case is = HAPPY BIRTHDAY
Helpful topics to understand this program better are-
2. C Program to convert a string from lower case to upper case
Let’s discuss the execution(kind of pseudocode) for the program to convert a string from lower case to upper case in C.
- Initially, the program will prompt the user to enter the string that needs to be converted.
- The string is now passed to a function
convertLowerToUpper()
. - In the
convertLowerToUpper()
function,For
loop is used to convert the entered string into an uppercase string andif
statement is used to check whether the characters are in lower case or not. - If the string is in the lower case then convert the string into the upper case by subtracting 32 from their ASCII value.
Let us now implement the above execution of the program to convert string from lower case to upper case.
#include <stdio.h> #include <string.h> char string[1000]; void convertLowerToUpper() { int i; for (i = 0; string[i] != '\0'; i++) { if (string[i] >= 'a' && string[i] <= 'z') { string[i] = string[i] - 32; } } } int main() { printf("\nEnter the string : "); gets(string); convertLowerToUpper(); printf("\nThe String in Upper Case = %s", string); return 0; }
Note: The above program can also be implemented using a while loop as well.
Output Enter the string : lower to upper The String in Upper Case = LOWER TO UPPER
3. Conclusion
In this C Programming example, we have discussed how to convert a string from lower case to upper case using the ASCII values.
Helpful Links
Please follow C Programming tutorials or the menu in the sidebar for the complete tutorial series.
Also for the example C programs please refer to C Programming Examples.
All examples are hosted on Github.
Recommended Books
An investment in knowledge always pays the best interest. I hope you like the tutorial. Do come back for more because learning paves way for a better understanding
Do not forget to share and Subscribe.
Happy coding!! ?