Check The Programming Section
Two ways we can convert a string to lower case string as follows:
using strlwr() library function from string.h
using tolower() function by converting each charcater to lowercase
using an iterative approach by converting each upper case character to lower case using ASCII values
Using strlwr() library function: this library function is not defined in C standard library and use of this function is compiler dependent. To use this we need to include string.h header file.
#include <stdio.h>
#include <string.h>
int main()
{
char info[]="Learn Programming";
strlwr(info);
printf("%s",info);
return 0;
}
Using tolower() library function: tolower() function is defined in ctype.h header file.This function accept one character and returns it lower case version.
#include <stdio.h>
#include <ctype.h>
int main()
{
char info[]="Learn Programming";
int i = 0;
while(info[i]!='\0'){
info[i] = tolower(info[i]);
i++;
}
printf("%s",info);
return 0;
}
Using ASCII values: In this approach, the ASCII values of all characters are checked. If any ASCII value is in between 65 and 90 then 32 is added and saved with that character.
#include <stdio.h>
int main()
{
char info[] = "Learn ProgrammiG";
int i = 0;
while(info[i]!='\0'){
if( info[i]>=65 && info[i]<=90)
info[i] = info[i]+32;
i++;
}
printf("The string after lowercase convertion:: %s",info);
return 0;
}