Write a C program to convert uppercase to lowercase letters without using string convert function

CServer Side ProgrammingProgramming

Before going to know about how to convert upper case to lower case letters without string convert function.

Let us have a look on program to convert upper to lower using convert function, then you will get a clarity on what we are doing in the program −

Example

#include <stdio.h>
#include <string.h>
int main(){
   char string[50];
   printf("enter a string to convert to lower case\n");
   gets(string); /reading the string
   printf("The string in lower case: %s\n", strlwr(string)); //strlwr converts all upper    to
   lower
   return 0;
}

Output

enter a string to convert to lower case
CProgramming LangUage
The string in lower case: cprogramming language

Now let's see the program to convert upper to lower without using predefined function −

Example

#include<stdio.h>
void main(){
   //Declaring variable for For loop (to read each position of alphabet) and string//
   int i;
   char string[40];
   //Reading string//
   printf("Enter the string : ");
   gets(string);
   //For loop to read each alphabet//
   for(i=0;string[i]!='\0';i++){
      if(string[i]>=65&&string[i]<=90){
         string[i]=string[i]+32;
      }
   }
   printf("The converted lower case string is : ");
   puts(string);
}

Output

Enter the string : TUTORIALSPOINT
The converted lower case string is : tutorialspoint
raja
Published on 08-Mar-2021 14:22:12
Advertisements