In this post, let’s see how to get the UPPERCASE string from the user and then convert to a lowercase string with space in C Program.
Let’s write the example C program to convert uppercase string to lowercase.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* * Convert uppercase to lowercase in C program * We need to use tolower() function * so lets include ctype.h */ #include<stdio.h> #include<ctype.h> #include<string.h> int main() { char inputStr[50], outputStr[50]; int i; //get the input from the user including space printf("Enter something in CAPS: "); scanf("%[^\n]%*c", inputStr); for(i=0; i < strlen(inputStr); i++) { //convert it to lowercase & store it in a variable outputStr[i] = tolower(inputStr[i]); } //print the lowercase printf("lowercase: %s", outputStr); } |
Sample output of the above example snippet is,
1 2 3 4 5 |
Enter something in CAPS: AGUR CHAND BABU lowercase: agur chand babu -------------------------------- Process exited after 4.795 seconds with return value 26 Press any key to continue . . . |
I hope this simple C program helps you to convert Uppercase to Lowercase.