C

Convert a String to Lowercase in C

In this tutorial, we are going to see how to convert a string to lowercase in C.
 

Convert a String to Lowercase in C
#include <stdio.h>
#include <string.h>

int main() {
   char str[100];
   int i;
   printf("\nEnter the string to convert to lower case: ");
   gets(str);
   for (i = 0; str[i]!='\0'; i++) {
     /* if the characters are in upper case, convert them to
 	    lower case by by adding 32 to their ASCII value. */
      if(str[i] >= 'A' && str[i] <= 'Z') {
         str[i] = str[i] +32;
      }
   }
   printf("\nThe string in lower case = %s", str);
   return 0;
}

Output:

Enter the string to convert to lower case: WELCOME TO STACKHOWTO!

The string in lower case = welcome to stackhowto!

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *