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.
/*
* 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,
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.