Let’s write an useful C program today. This C Program will convert any Uppercase string to Lowercase.
For this, we are going to use tolower() function which is already available in C itself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <stdio.h> int main() { char mystr[100]; int i=0; //print about the program printf("C Program to convert uppercase to lowercase\n"); printf("Enter your full name in CAPS: "); //get the input string from user fgets(mystr, 100, stdin); //loop through the string and convert into lower letters while( mystr[i] ) { //store back the lower letter to mystr mystr[i] = tolower(mystr[i]); i++; } //print the lower letters printf("Lowercase: %s", mystr); } |
Read the comments in the above program to understand how it works.
Output of the above program will be:
1 2 3 |
C Program to convert uppercase to lowercase Enter your full name in CAPS: AGURCHAND BABU Lowercase: agurchand babu |
Enjoy the day!