C Program to Convert String to Lowercase Using User Defined Function

This C program converts all uppercase letters in the given string to lowercase using user defined function and without using string handling function strlwr().

C Source Code: String to Lowercase User Defined Function


#include<stdio.h>

/* Function Prototype */
void mystrlwr(char str[40]);

/* Main Function */
void main()
{
 char str[40];
 int i;

 printf("Enter string:\n");
 gets(str);
 mystrlwr(str);
 printf("String in lowercase is:\n");
 puts(str);
 
 retrun 0;
}

/* Function Definition */
void mystrlwr(char str[40])
{
 int i;
 for(i=0;str[i]!='\0';i++)
 {
  if(str[i]>='A'&& str[i]<='Z')
  {
   str[i] = str[i]+32;
  }
 }
}

Output

Enter string:
WeLcOmE To C 101. ↲
String in lowercase is:
welcome to c 101.